public final class ResourceUtils extends Object
Modifier and Type | Method and Description |
---|---|
static ResourceBundle |
getBundledResource(Class<?> c)
This method takes a class and returns a
ResourceBundle which is
loaded from a properties file with the same base name as the class. |
static ResourceBundle |
getBundledResource(Class<?> c,
String baseName)
This method returns a
ResourceBundle which is loaded from
a properties file with the specified base name from the same package
as the specified class. |
public static ResourceBundle getBundledResource(Class<?> c)
ResourceBundle
which is
loaded from a properties file with the same base name as the class.
Note that both the class and the properties file(s) need to be in the
same jar file.
For example, supposing the jar file contains:
com/hp/util/example/SomeObject.class com/hp/util/example/SomeObject.propertiesThen, to correctly load the resource bundle associated with
SomeObject
, call:
ResourceBundle res = ResourceUtils.getBundledResource(SomeObject.class);Note that no error is thrown if the properties file does not exist. This condition will not become apparent until you try and access a property from the bundle, at which time a
MissingResourceException
will be thrown.c
- the classpublic static ResourceBundle getBundledResource(Class<?> c, String baseName)
ResourceBundle
which is loaded from
a properties file with the specified base name from the same package
as the specified class.
Note that both the class and the properties file(s) need to be in the
same jar file.
For example, supposing the jar file contains:
com/hp/nis/util/example/SomeObject.class com/hp/nis/util/example/DisplayStrings.propertiesThen, to correctly load the resource bundle call:
ResourceBundle res = ResourceUtils.getBundledResource(SomeObject.class, "DisplayStrings");Note that no error is thrown if the properties file does not exist. This condition will not become apparent until you try and access a property from the bundle, at which time a
MissingResourceException
will be thrown.c
- the class requesting the bundlebaseName
- the base name of the resource bundleCopyright © 2015. All Rights Reserved.