Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.util.Properties encoding

Tags:

java

I get different results on two different systems and don't know why.

Properties prop = new Properties();
prop.load(new ByteArrayInputStream(input)); //input is byte[]

On both systems input contains "var=\\u00C4\\u00DC\\u00D6\\u00E4\\u00FC\\u00F6".

On my test system prop contains "var=ÄÜÖäüö". (This is what I want)

On another system prop contains "var=\xC4\xDC\xD6\xE4\xFC\xF6". This is input in hex, but why does Properties do this? I unfortunately know nothing about the other systems configuration.

Has someone an idea about the reason?

like image 884
unknown Avatar asked Oct 29 '25 11:10

unknown


1 Answers

Java .properties files are encoded with ISO-8859-1 (Latin-1), NOT UTF-8. All non-Latin-1 characters must be entered by using Unicode escape characters, e.g. \uHHHH.

An alternative is to use the XML format for properties, which IS UTF-8.

Source: Javadoc

Also see this SO question

And this one

like image 158
Stewart Avatar answered Nov 01 '25 02:11

Stewart