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?

vico
  • 17,051
  • 45
  • 159
  • 315

4 Answers4

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
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

Community
  • 1
  • 1
Simone Zandara
  • 9,401
  • 2
  • 19
  • 26
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.

Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137
1

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

Sizik
  • 1,066
  • 5
  • 11