package org.kodejava.util;
import java.util.*;
public class ResourceBundleToProperties {
public static void main(String[] args) {
// Load resource bundle Messages_en_GB.properties from the classpath.
ResourceBundle resource = ResourceBundle.getBundle("Messages", Locale.UK);
// Call the convertResourceBundleToProperties method to convert the resource
// bundle into a Properties object.
Properties properties = convertResourceBundleToProperties(resource);
// Print the entire contents of the Properties.
Enumeration<Object> keys = properties.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String value = (String) properties.get(key);
System.out.println(key + " = " + value);
}
}
/**
* Convert ResourceBundle into a Properties object.
*
* @param resource a resource bundle to convert.
* @return Properties a properties version of the resource bundle.
*/
private static Properties convertResourceBundleToProperties(ResourceBundle resource) {
Properties properties = new Properties();
Enumeration<String> keys = resource.getKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
properties.put(key, resource.getString(key));
}
return properties;
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024