187 Java PropertyResourceBundle Class
Introduction
The Java PropertyResourceBundle class is a concrete subclass of ResourceBundle that manages resources for a locale using a set of static strings from a property file.Following are the important points about PropertyResourceBundle −
The class can be constructed either from an InputStream or a Reader, which represents a property file.
Class declaration
Following is the declaration for java.util.PropertyResourceBundle class −
public class PropertyResourceBundle extends ResourceBundle
Field
Fields inherited from class java.util.ResourceBundle.
Class constructors
| Sr.No. | Constructor & Description |
|---|---|
| 1 | PropertyResourceBundle(InputStream stream) This creates a property resource bundle from an InputStream. |
| 2 | PropertyResourceBundle(Reader reader) This creates a property resource bundle from a Reader. |
Class methods
| Sr.No. | Method & Description |
|---|---|
| 1 | Enumeration<String> getKeys() This method returns an Enumeration of the keys contained in this ResourceBundle and its parent bundles. |
| 2 | Object handleGetObject(String key) This method gets an object for the given key from this resource bundle. |
| 3 | protected Set<String> handleKeySet() This method returns a Set of the keys contained only in this ResourceBundle. |
Methods inherited
This class inherits methods from the following classes −
- java.util.ResourceBundle
- java.util.Object
Getting Keys from a PropertyResourceBundle Instance Example
The following example shows the usage of Java PropertyResourceBundle getKeys() method. We created a InputStream of given content and then using that stream a PropertyResourceBundle object is created. Then using getKeys() method, an enumeration of keys is retrieved and entries are printed.
Output
Let us compile and run the above program, this will produce the following result −
Bundle key: s2 Bundle key: s1 Bundle key: s3

Comments
Post a Comment