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.