-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1
-
x86
-
windows_95
Name: mc57594 Date: 01/29/97
The documentation for ResourceBundle describes in detail
the class lookup strategy for the getResourceBundle method but
does not mention that a properties file may be used instead of
a class and that a PropertyResourceBundle will be returned instead.
Furthermore, the documentation for PropertyResourceBundle makes
no mention of this fact and leads the reader to believe that the
only way of getting a PropertyResourceBundle is to use the constructor.
Using the constructor means we don't get the benefit of the lookup
strategy used by getResourceBundle method.
Assume that we have a properties file called 'resource.properties'
located in the directory 'sample/package' relative to the current
directory. Assume also that the current directory is on the CLASSPATH.
The test application below shows that the call:
getResourceBundle("sample.package.resource", null)
finds and loads the properties file and returns a PropertyResourceBundle
as a result.
Test application Test2.java:
import java.util.*;
public class Test2 {
public static void main(String args[]) {
ResourceBundle res =
ResourceBundle.getResourceBundle("sample.package.resource", null);
System.out.println("Object 'res' is an instance of " +
res.getClass().getName());
System.out.println("The value of 'string1' in 'res' is '" +
res.getString("string1") + "'");
System.exit(0);
}
}
Resource file: resource.properties (locate in sample/package directory)
# resource.properties: sample for class Test2
string1=Sample string number one.
Output:
Object 'res' is an instance of java.util.PropertyResourceBundle
The value of 'string1' in 'res' is 'Sample string number one.'
======================================================================
- duplicates
-
JDK-4314141 Need full specification of ResourceBundle.getBundle
-
- Resolved
-