How to escape special characters in the key of properties file

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

I am using a property(key = value) like give names: (1) code = xxx in the properties file but when i tried to get that key it is giving error as "No message found under code give names: (1) code = xxx

I tried it by escaping the whitespace with \ but it wont worked. do I need to escape :,(, and ) characters also. Please suggest how to proceed

Thanks

回答1:

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.



回答2:

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

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!