GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||
GeezerVison is showing www.tutorialspoint.com — Java ResourceBundle Class
Selected Reading
Java ResourceBundle ClassIntroductionThe Java ResourceBundle class contain locale-specific objects.Following are the important points about ResourceBundle −
Class declarationFollowing is the declaration for java.util.ResourceBundle class − public abstract class ResourceBundle extends Object FieldFollowing are the fields for java.util.ResourceBundle class − protected ResourceBundle parent − This is the parent bundle of this bundle. Class constructors
Class methods
Methods inheritedThis class inherits methods from the following classes −
Getting Keys of a ResourceBundle ExampleThe following example shows the usage of Java ResourceBundle getKeys() method to print list of keys present in the properties file. We've created a resource bundle of US Locale for the corresponding hello_en_US.properties file. Then we printed the text assigned to key hello. Then the enumeration of keys is retrieved using getKeys() method and keys are printed. package com.tutorialspoint;
import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;
public class ResourceBundleDemo {
public static void main(String[] args) {
// create a new ResourceBundle with specified locale
ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);
// print the text assigned to key "hello"
System.out.println("" + bundle.getString("hello"));
// get the keys
Enumeration<String> enumeration = bundle.getKeys();
// print all the keys
while (enumeration.hasMoreElements()) {
System.out.println("" + enumeration.nextElement());
}
}
}
OutputAssuming we have a resource file hello_en_US.properties available in your CLASSPATH, with the following content. This file will be used as an input for our example program − hello = Hello World! bye = Goodbye World! morning = Good Morning World! 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. |