java.util.PropertyResourceBundle.handleKeySet()方法實例
java.util.PropertyResourceBundle.handleKeySet() 方法返回這個資源包(這不包括在父包鍵)的鍵集合。
聲明
以下是java.util.PropertyResourceBundle.handleKeySet()方法的聲明
protected SethandleKeySet()
參數
NA返回值
此方法返回 返回鍵集合。
異常
NA例子
下麵的示例演示java.util.PropertyResourceBundle.handleKeySet()方法的用法。
package com.yiibai; import java.io.IOException; import java.io.InputStream; import java.io.StringBufferInputStream; import java.util.Enumeration; import java.util.Iterator; import java.util.PropertyResourceBundle; import java.util.Set; public class PropertyResourceBundleDemo { public static void main(String[] args) { // Prepare content for simulating property files String fileContent = "# Integer value 1 " + "s1=1 " + "# String value PropertyResourceBundleDemo " + "s2=PropertyResourceBundleDemo " + "# Date value Fri Jan 31 00:00:00 IST 3913 " + "s3=Fri Jan 31 00:00:00 IST 3913"; InputStream propStream = new StringBufferInputStream(fileContent); try { // Create property resource bundle PropertyResourceBundle bundle = new PropertyResourceBundle(propStream); // Get resource key set SetkeySet = bundle.handleKeySet(); Iterator keys = keySet.iterator(); while(keys.hasNext()) { System.out.println("Bundle key: "+keys.next()); } } catch (IOException e) { e.printStackTrace(); } } }
讓我們來編譯和運行上麵的程序,這將產生以下結果:
Bundle key: s2 Bundle key: s1 Bundle key: s3