0

I have a requirement to read the Properties file with Strings having Romanian Characters.

When I try to do the encoding, I see some of the characters are not encoded properly.

    ResourceBundle bundle = ResourceBundle.getBundle("view.Country");
    Enumeration keys = bundle.getKeys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        String value = bundle.getString(key);
        try {
            System.out.println(key + ": " + new String(value.getBytes("UTF-8"), "UTF-8"));
            System.out.println("-----------");
            System.out.println(key + ": " + new String(value.getBytes("Windows-1250"), "Windows-1250"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

Input:

Country=România
AdministrativeAreaType=Țara

Output:

AdministrativeAreaType: ?ara
-----------
AdministrativeAreaType: ?ara
Country: România
-----------
Country: România

As you can see in the output, the country value is encoded properly. But the AdministrativeAreaType value is not encoded properly.

Please let me know if there is anything wrong in the code.

Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
  • one reason. the input file is not UTF-8 or UNICODE. and on another note have you tried ResourceBUndle with Locale. Like in this example http://www.avajava.com/tutorials/lessons/how-do-i-use-locales-and-resource-bundles-to-internationalize-my-application.html – Acewin Oct 20 '15 at 07:08
  • A ResourceBundle file is always in ISO-8859-1 encoding. You probably saved the file in a different encoding. – Erwin Bolwidt Oct 20 '15 at 07:09
  • Possible duplicate of [How to use UTF-8 in resource properties with ResourceBundle](http://stackoverflow.com/questions/4659929/how-to-use-utf-8-in-resource-properties-with-resourcebundle) – Erwin Bolwidt Oct 20 '15 at 07:09
  • Also please check this discussion http://stackoverflow.com/questions/10933620/display-special-characters-using-system-out-println – Acewin Oct 20 '15 at 07:10

1 Answers1

1

As other fellow members of the community suggested, Romanian is not a language supported by UTF-8 or UNICODE.

I would recommend having a look at the list of Supported Encodings. Romanian should be covered by ISO-8859-2.

I am not sure, but I am guessing you will be required to make the conversion yourself.

bgguna
  • 19
  • 5