GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Technologies
  • Databases
  • Computer Programming
  • Web Development
  • Java Technologies
  • Computer Science
  • Mobile Development
  • Big Data & Analytics
  • Microsoft Technologies
  • DevOps
  • Latest Technologies
  • Machine Learning
  • Digital Marketing
  • Software Quality

This view

  • Original page
  • New address

GeezerVison is showing www.tutorialspoint.com — Java PropertyResourceBundle Class

Java.util package tutorial
  • Java.util - Home
  • Java.util - ArrayDeque
  • Java.util - ArrayList
  • Java.util - Arrays
  • Java.util - BitSet
  • Java.util - Calendar
  • Java.util - Collections
  • Java.util - Currency
  • Java.util - Date
  • Java.util - Dictionary
  • Java.util - EnumMap
  • Java.util - EnumSet
  • Java.util - Formatter
  • Java.util - GregorianCalendar
  • Java.util - HashMap
  • Java.util - HashSet
  • Java.util - Hashtable
  • Java.util - IdentityHashMap
  • Java.util - LinkedHashMap
  • Java.util - LinkedHashSet
  • Java.util - LinkedList
  • Java.util - ListResourceBundle
  • Java.util - Locale
  • Java.util - Observable
  • Java.util - PriorityQueue
  • Java.util - Properties
  • Java.util - PropertyPermission
  • Java.util - PropertyResourceBundle
  • Java.util - Random
  • Java.util - ResourceBundle
  • Java.util - ResourceBundle.Control
  • Java.util - Scanner
  • Java.util - ServiceLoader
  • Java.util - SimpleTimeZone
  • Java.util - Stack
  • Java.util - StringTokenizer
  • Java.util - Timer
  • Java.util - TimerTask
  • Java.util - TimeZone
  • Java.util - TreeMap
  • Java.util - TreeSet
  • Java.util - UUID
  • Java.util - Vector
  • Java.util - WeakHashMap
  • Java.util - Interfaces
  • Java.util - Exceptions
  • Java.util - Enumerations
  • Java.util Useful Resources
  • Java.util - Useful Resources
  • Java.util - Discussion
Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Online Resume Builder
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

Java PropertyResourceBundle Class



Previous
Quiz
Next

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.

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
Tutorix - AI Tutor
Previous Quiz Next
Advertisements
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.