A ResourceBundle offers a very easy way to access key/value pairs in a properties file in a JavaSW
application. As a demonstration of this, I created the
ResourceBundleTest class and a src/test/bundletest/mybundle.properties
file in a project, as shown here:
The ResourceBundleTest class references the mybundle.properties file
via the ResourceBundle.getBundle("test.bundletest.mybundle") method
call. Notice that the package of the properties file is specified (using
.'s instead of /'s) and that the properties file name is specified
without the .properties extension.
After getting the resource bundle, the ResourceBundleTest class
iterates over all of the keys in mybundle.properties and displays each
of the keys and its value.
ReadPropertiesFile.java
mybundle.properties
Read a properties file with a Resource Bundle
Labels: Interview Questions, Java SE 6
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment