3

I have property with string that contains some special characters. After I save it to properties file I have:

BB\u0161BB=0 

I don't like character represented with \u0161 . Why it can't save like character I see it on the screen and type from keyboard?

UPD What is the easiest way to read ini-file architecture file that contains special character?

4 Answers 4

3

That's how Properties files are defined to behave. Any other system is likely to use UTF-8 which might not be readable either.

As your character is outside the range of an ISO-8859-1 encoding, it has to use unicode instead.

Sign up to request clarification or add additional context in comments.

Comments

2

You can!

Encode your file in unicode (UTF-8, for instance) using another application (Notepad++ is nice, for instance) and read your properties file like this:

File file = ... ; Properties properties = new Properties(); try (FileInputStream in = new FileInputStream(file); Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8)) { properties.load(reader); } // use properties 

There you go, properties file in any charset that you can read and use.

Comments

2

You can't. From javadoc:

...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 as defined in section 3.3 of The Java™ Language Specification; only a single 'u' character is allowed in an escape sequence.

Please refer to this How to use UTF-8 in resource properties with ResourceBundle

Comments

1

Properties files are ISO-8859-1 encoded, so characters outside of that set need to be \uXXXX escaped.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.