- Java.util 包类
- Java.util - 首页
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util 包额外内容
- Java.util - 接口
- Java.util - 异常
- Java.util - 枚举
- Java.util 有用资源
- Java.util - 有用资源
- Java.util - 讨论
Java PropertyResourceBundle handleKeySet() 方法
描述
Java PropertyResourceBundle handleKeySet() 方法返回此资源包的键集(不包括父包中的键)。
声明
以下是 java.util.PropertyResourceBundle.handleKeySet() 方法的声明
protected Set<String> handleKeySet()
参数
无
返回值
此方法返回此资源包及其父包的键。
异常
无
从字节流实例中获取 PropertyResourceBundle 键的示例
以下示例演示了 Java PropertyResourceBundle handleKeySet() 方法的用法。我们创建了一个给定内容的 InputStream,然后使用该流创建了一个 PropertyResourceBundle 对象。然后使用 handleKeySet() 方法检索键集并打印条目。
package com.tutorialspoint; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.StringBufferInputStream; import java.nio.charset.Charset; import java.util.PropertyResourceBundle; public class PropertyResourceBundleDemo { public static void main(String[] args) { // Prepare content for simulating property files String fileContent = "# Integer value 1\n" + "s1 = 1\n" + "# String value PropertyResourceBundleDemo\n" + "s2 = PropertyResourceBundleDemo\n" + "# Date value Fri Jan 31 00:00:00 IST 3913\n" + "s3 = Fri Jan 31 00:00:00 IST 3913"; InputStream propStream = new ByteArrayInputStream(fileContent.getBytes (Charset.forName("UTF-8"))); try { // Create property resource bundle PropertyResourceBundle bundle = new PropertyResourceBundle(propStream); // Get resource key set Set<String> keySet = bundle.handleKeySet(); Iterator<String> 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
从 StringReader 实例中获取 PropertyResourceBundle 键的示例
以下示例演示了 Java PropertyResourceBundle handleKeySet() 方法的用法。我们创建了一个给定内容的 StringReader,然后使用该读取器创建了一个 PropertyResourceBundle 对象。然后使用 handleKeySet() 方法检索键集并打印条目。
package com.tutorialspoint; import java.io.IOException; import java.io.StringReader; import java.util.PropertyResourceBundle; public class PropertyResourceBundleDemo { public static void main(String[] args) { // Prepare content for simulating property files String fileContent = "# Integer value 1\n" + "s1 = 1\n" + "# String value PropertyResourceBundleDemo\n" + "s2 = PropertyResourceBundleDemo\n" + "# Date value Fri Jan 31 00:00:00 IST 3913\n" + "s3 = Fri Jan 31 00:00:00 IST 3913"; StringReader reader = new StringReader(fileContent); try { // Create property resource bundle PropertyResourceBundle bundle = new PropertyResourceBundle(reader); // Get resource key set Set<String> keySet = bundle.handleKeySet(); Iterator<String> 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
java_util_propertyresourcebundle.htm
广告