A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/java/util/java_util_propertyresourcebundle.htm below:

Java PropertyResourceBundle Class

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 −

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 Methods inherited

This class inherits methods from the following classes −

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.

package com.tutorialspoint;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.PropertyResourceBundle;

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 ByteArrayInputStream(fileContent.getBytes
         (Charset.forName("UTF-8")));

      try {
      
         // Create property resource bundle
         PropertyResourceBundle bundle = 
         new PropertyResourceBundle(propStream);

         // Get resource keys
         Enumeration<String> keys = bundle.getKeys();

         while(keys.hasMoreElements()) {
            System.out.println("Bundle key: "+keys.nextElement());
         }
      } catch (IOException e) {
         e.printStackTrace();
      }  
   }
}
Output

Let us compile and run the above program, this will produce the following result −

Bundle key: s2
Bundle key: s1
Bundle key: s3

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4