Java PropertyResourceBundle .getKeys ()

Syntax

PropertyResourceBundle.getKeys() has the following syntax.

public Enumeration <String> getKeys()

Example

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


//  w  w  w.jav  a2  s  .  c o m
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.Enumeration;
import java.util.PropertyResourceBundle;

public class Main {
  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";
    InputStream propStream = new StringBufferInputStream(fileContent);

    PropertyResourceBundle bundle = new PropertyResourceBundle(propStream);

    // Get resource keys
    Enumeration keys = bundle.getKeys();
    while (keys.hasMoreElements()) {
      System.out.println("Bundle key: " + keys.nextElement());
    }
  }

}

The code above generates the following result.