Java: How to write "Arabic" in properties file?

http://sourceforge.net/projects/eclipse-rbe/

You can use the above plugin for eclipse IDE to make the Unicode conversion for you.


As described in the class reference for "Properties"

The load(Reader) / store(Writer, String) methods load and store properties from and to a character based stream in a simple line-oriented format specified below. The load(InputStream) / store(OutputStream, String) methods work the same way as the load(Reader)/store(Writer, String) pair, except the input/output stream is encoded in ISO 8859-1 character encoding. Characters that cannot be directly represented in this encoding can be written using Unicode escapes ; only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.


Properties-based resource bundles must be encoded in ISO-8859-1 to use the default loading mechanism, but I have successfully used this code to allow the properties files to be encoded 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 have to change the encoding of the file itself to UTF-8 in your IDE, and can use it like this:

ResourceBundle bundle = ResourceBundle.getBundle(
    "package.Bundle", new ResourceControl());