Java PropertyResourceBundle .handleKeySet ()

Syntax

PropertyResourceBundle.handleKeySet() has the following syntax.

protected Set <String> handleKeySet()

Example

In the following code shows how to use PropertyResourceBundle.handleKeySet() method.


import java.io.IOException;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.Iterator;
import java.util.PropertyResourceBundle;
import java.util.Set;
/* w w w  . j  a  v  a  2 s . com*/
public class Main extends PropertyResourceBundle {
  public Main(InputStream stream) throws IOException {
    super(stream);
  }

  public static void main(String[] args) throws Exception {
    // Prepare content for simulating property files
    String fileContent = "s1=1\n" + "s2=Main\n"
        + "s3=Fri Jan 31 00:00:00 IST 3913";
    InputStream propStream = new StringBufferInputStream(fileContent);

    // Create property resource bundle
    Main bundle = new Main(propStream);

    // Get resource key set
    Set keySet = bundle.handleKeySet();
    Iterator keys = keySet.iterator();
    while (keys.hasNext()) {
      System.out.println("Bundle key: " + keys.next());
    }

  }
}

The code above generates the following result.