Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java properties file specs [duplicate]

Possible Duplicate:
Escaping equal sign in properties files

In a .properties file, can I use the character '=' after the first 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.

like image 544
Gugussee Avatar asked Jan 12 '11 14:01

Gugussee


People also ask

How delete properties file in Java?

util. Properties. clear() method is used to remove all the elements from this Properties instance. Using the clear() method only clears all the element from the Properties and does not delete the Properties.

What is the advantage of properties file in Java?

properties is a file extension for files mainly used in Java-related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.


2 Answers

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

like image 182
Lukasz Avatar answered Nov 15 '22 17:11

Lukasz


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.

like image 25
JB Nizet Avatar answered Nov 15 '22 17:11

JB Nizet