Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 559
bl4ckb0l7 Avatar asked Jan 21 '10 09:01

bl4ckb0l7


People also ask

What is a property key Java?

Properties keys() method in Java with Examples The keys() method of Properties class is used to get the enumeration of the keys in this Properties object. This enumeration can be used to traverse and iterate the keys sequentially.

How do you check if a key exists in properties file Java?

Just load the properties file and then try to get the desired property. Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns null if the property is not found.


1 Answers

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" 
like image 67
Veaceslav Serghienco Avatar answered Oct 08 '22 02:10

Veaceslav Serghienco