Apache commons configuration configuration before the character ","

I want to load the configuration (apache commons configuration) from the properties file. My program:

PropertiesConfiguration pc = new PropertiesConfiguration("my.properties"); System.out.println(pc.getString("myValue")); 

In my.properties I have

  myValue=value, 

with a comma

When I run the program, the output is value , not value, with comma . It looks like the value is loading before the character,.

Any ideas?

+15
java apache-commons apache-config
source share
5 answers

Check out the Javadoc . You must set setDelimiterParsingDisabled (true) to disable property list parsing.

+9
source share

This behavior is clearly documented , that is, that a PropertiesConfiguration treats a semicolon value as multiple values ​​that allow things like:

 fruit=apples,banana,oranges 

interpret intelligently. The fix (from the document) is to add a backslash to escape the comma, e.g.

 myKey=value\, with an escaped comma 
+13
source share

Actually propConfig.setDelimiterParsingDisabled (true) works, but after this parameter you should load the configuration file, for example:

 propConfig = new PropertiesConfiguration(); propConfig.setDelimiterParsingDisabled(true); propConfig.load(propertiesFile); 

if your code looks like:

propConfig = new PropertiesConfiguration (propertiesFile); propConfig.setDelimiterParsingDisabled (true);

then the setup will not work

+3
source share

PropertiesConfiguration interprets ',' as a separator of values.

0
source share

If you put \ in front of , you will escape it, and you can read the value

Example:

 myValue=value\, with comma 

You read = value, with comma no problem

0
source share

All Articles