Read a properties file with a Resource Bundle

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:
'testing' project 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

0 comments: