Class PropertyResourceBundle in Java

Class PropertyResourceBundle in Java

PropertyResourceBundle class is a concrete subclass of ResourceBundle. It reads a Properties file from a specified InputStream and implements the ResourceBundle API for looking up named resources from the resulting Properties object.

The PropertyResourceBundle class is a concrete subclass of ResourceBundle that represents a set of resources for a locale. The resources are specified as a set of key/value string pairs in a property file. Internally, a Properties object is used to retrieve the resources from the property file.

When ResourceBundle.getBundle() is called, it attempts to find a resource bundle that most
closely matches a particular locale. This can be either a ListResourceBundle subclass or a property file, represented by a PropertyResourceBundle. Once the resource bundle has been retrieved, its contents can be used by the application to present locale-specific information.

PropertyResourceBundle inherits a lot of functionality from ResourceBundle; see the class
description of ResourceBundle for more information.

A Properties file contains lines of the form:

Each such line defines a named property with the specified String value.

Although we can instantiate a PropertyResourceBundle yourself, it is more common to simply define a Properties file, and then allow ResourceBundle.getBundle() to look up that file and return the necessary PropertyResourceBundle object.

The class structure for PropertyResourceBundle is given as

public class java.util.PropertyResourceBundle extends java.util.ResourceBundle{
// Public Constructor
public PropertyResourceBundle(InputStream stream) throws IOException;
// Public Instance Methods
public Enumeration getKeys(); // Defines ResourceBundle
public Object handleGetObject(String key); // Defines ResourceBundle

The details of the class structure are given as follows:

public PropertyResourceBundle(InputStream stream);

public PropertyResourceBundle(InputStream stream) constructor creates a PropertyResourceBundle that reads properties from the given input stream.

See also  Class Socket in Java

stream – The input stream to use.

public Enumeration getKeys();

public Enumeration getKeys() method returns an Enumeration that iterates through the keys in this

This method returns the keys in the resource bundle as an Enumeration.

public Object handleGetObject(String key);

public Object handleGetObject(String key) method returns the resource that corresponds to the given key.

This method returns the resource that corresponds to this key.

key – The key of the resource to retrieve.

Apart from these PropertyResourceBundle class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)

PropertyResourceBundle class also has inherited methods from ResourceBundle. They are as follows:

  • getObject(String)
  • getStringArray(String)
  • setParent(ResourceBundle)
  • getString(String)

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *