12

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.

Community
  • 1
  • 1
Gugussee
  • 1,673
  • 3
  • 16
  • 26
  • 2
    duplicate of http://stackoverflow.com/questions/2406975/escaping-equal-sign-in-properties-files – bluish Jan 12 '11 at 14:23

2 Answers2

12

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.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
9

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

Lukasz
  • 7,572
  • 4
  • 41
  • 50
  • 5
    This is NOT correct. You don't need to escape your `=` and `:` characters, unless they're in the KEY of the property, instead of the VALUE. – Dawood ibn Kareem Oct 11 '16 at 18:13
  • Yes, as @DawoodibnKareem says, this is not correct. Only when the value starts with : you have to escape it otherwise \ is ignored – ACV Jul 24 '17 at 12:05
  • 1
    I wrote "you may put" not "you should". Besides that I pasted default behaviour of Java6 Properties store() method. – Lukasz Jul 29 '18 at 10:37