简体   繁体   English

如何在属性文件的键中转义特殊字符?

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

I've got a key = value property in the .properties file: 我在.properties文件中有一个key = value属性:

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 在代码下找不到消息,给出了名称:(1)代码= 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) 您可以签出: 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. 有关java如何解释属性文件的信息。 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 '\\\\' 例如:如果您的单词包含'$'字符(例如Rf $ RF,则可以使用两个前导'\\\\'对其进行转义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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