开发者

Java properties file specs [duplicate]

开发者 https://www.devze.com 2023-02-03 16:24 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Escaping equal sign in properties files
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Escaping equal sign in properties files

In a .properties file, can I use the character '=' after the firs开发者_StackOverflow中文版t one?

Like this:

url=http://www.example.org/test=

Is it allowed and where can I know that it is allowed if it indeed is?

So far it seems to be working but I simply am not too sure it won't break later on.


Unless they change the spec of Properties, it will always work. See http://download.oracle.com/javase/6/docs/api/java/util/Properties.html#load%28java.io.Reader%29 for the specs.


You may put backslash escape character (\) before = and :.

Or better use the following code that prints out how your property should be escaped:

                Properties props = new Properties();
                props.setProperty("url", "http://www.example.org/test=");
                props.store(System.out, null);

Output:

#Wed Jan 12 14:30:39 GMT 2011
url=http\://www.example.org/test\=

Also, please check out Java API information

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号