How to escape special characters in a property file key?

I have a key = value property in a .properties file:

 give names: (1) code = xxx 

... but when I tried to get this key, it gave an error:

No messages found under code, give names: (1) code = xxx

I tried to break out of the gap with \ but it didn't work.

Do I need to escape the characters : ( , and ) ?

+6
source share
2 answers

You can check: http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load(java.io.Reader)

Information about how java interprets the properties file. The most important part:

The key contains all characters in the line starting with the first non-white space, and up to, but not including, the first character without the character "=", ":" or "space", other than the line terminator.

+15
source

In my case, the two leading "\\" work fine for me.

For example: if your word contains the character "$" (for example, Rf $ RF, you can avoid it with two leading "\\"

+1
source

Source: https://habr.com/ru/post/947309/


All Articles