Java.util.Property ResourceBundle.handleKeySet()


描述

所述java.util.PropertyResourceBundle.handleKeySet()方法返回的密钥集合此资源包的(这不包括在父束键)。

声明

以下是java.util.PropertyResourceBundle.handleKeySet()方法的声明

protected Set<String> handleKeySet()

参数

NA

返回值

此方法返回返回键组。

异常

NA

实例

以下示例显示了java.util.PropertyResourceBundle.handleKeySet()方法的用法。

package com.tutorialspoint;

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\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 StringBufferInputStream(fileContent);

      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