Property-based resource packages must be encoded in ISO-8859-1 to use the default loading mechanism, but I have successfully used this code to enable encoding of property files in UTF-8:
private static class ResourceControl extends ResourceBundle.Control { @Override public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { String bundlename = toBundleName(baseName, locale); String resName = toResourceName(bundlename, "properties"); InputStream stream = loader.getResourceAsStream(resName); return new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8")); } }
Then, of course, you must change the encoding of the file itself to UTF-8 in your IDE and you can use it as follows:
ResourceBundle bundle = ResourceBundle.getBundle( "package.Bundle", new ResourceControl());
Michael borgwardt
source share