10

I've got a key = value property in the .properties file:

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

I tried escaping the whitespace with \ but it didn't work.

Do I need to escape :,(, and ) characters as well?

Genhis
  • 1,484
  • 3
  • 27
  • 29
user1169474
  • 191
  • 1
  • 1
  • 6
  • Which class are you taking about? Properties has no such error message. If you get a stack trace, can you include it in your question? – Peter Lawrey Jun 14 '13 at 15:00
  • 1
    Yes you need to escape : and space otherwise it's consider as the end of the key. Check http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load%28java.io.Reader%29 – alain.janinm Jun 14 '13 at 15:02
  • If you want to programmatically escape the value for properties, see https://stackoverflow.com/a/57983519/2411506 – DanielCuadra Sep 18 '19 at 00:31

2 Answers2

22

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.

Emil L
  • 20,219
  • 3
  • 44
  • 65
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 '\\'