简体   繁体   中英

How to escape special characters in the key of properties file?

I've got a key = value property in the .properties file:

give names: (1) code = xxx

... but when I tried to get that key, it threw an error:

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

I tried escaping the whitespace with \\ but it didn't work.

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

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

For info on how java interprets a properties file. The most relevant part is:

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

In my case, two leading '\\\\' working fine for me.

For example : if your word contains the '$' character (eg Rf$RF, you can escape it with two leading '\\\\'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM