javawaveblogs-20

Tuesday, March 3, 2009

Java utility to read from resource bundle or properties file



/**
* dataSource.properties is loaded to a resource bundle.
*/
public static ResourceBundle resourceBundle = ResourceBundle.getBundle(
"sample.prop.health");

/**
* This method will return the value of the property from the resource
* bundle.
*
* @param key
* property key
* @return property value
*/
public static String getProperty(String key)
{
String value = null;
try
{
value = resourceBundle.getString(key);
}
catch (MissingResourceException missingResourceException)
{
Logger.getLogger(Utility.class.getName()).
log(Level.SEVERE,
"Resource Bundle not found",
missingResourceException);
}
return value;
}

No comments:

diggthis