Can the key in a Java property include a blank character?

bl4ckb0l7 picture bl4ckb0l7 · Jan 21, 2010 · Viewed 74.8k times · Source

We are getting properties (that we can not influence) out of a database and want to access them by a key/value mapping. We are facing the problem that one of the property keys includes a blank character.

foo bar = barefoot

This is - correctly - interpreted as follows

key: foo
value: bar = barefoot

Is there a way to include the blank in the key so that it's not interpreted as the delimiter? I guess this behaviour is just like intended, but I thought I could give it a try here.

Answer

Veaceslav Serghienco picture Veaceslav Serghienco · Jun 14, 2012

You can escape every thing in properties file with Java Unicode:

  • \u003d for =
  • \u0020 for whitespace

For example:

foo bar = barefoot

must be:

foo\u0020bar\u0020=\u0020barefoot

So will be:

key: "foo bar "
value: " barefoot"