I am using PropertiesConfiguration for loading and storing property values.
If I use character \'/\' in Property value, it gets saved as\'\\/\'. Could you please help me
I used 1.10 version of commons-configuration and works fine:
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
Are you sure it doesn't look like
PropName=jdbc\:sqlserver\://
and you typed this question in from memory? /
is not noramally an escaped character in a properties file, but :
is.
Perhaps the fact that you're not using a java.util.Properties file has a lot to do with it. The writers of PropertiesConfiguration
probably modified the load / store slightly to create properties files which better handle the /
character when read in as shell scripts.
Some systems read in properties files as "sourced shell scripts" to provide shell oriented command line tools which are compatible with the settings of the java program's properties files. If this is the case, then escaping the /
would prevent it from being interperted as a directory separator in certain contexts in the shell script.
This is because "/" has to be escaped for it to read back into the system. You could open the file back up and unscape those values but it would cause problems for you the next time you tried to open it.
Regarding Joachim's answer, I have looked at the javadoc to which he linked, and I even followed the links posted therein to the Java Language reference, and nowhere do I see where a slash ('/') in a property value would need to be escaped. When I use a java.util.Properties, with its methods load() and save(), slashes in property values are not escaped. For that matter, neither are colons (':') if used after the first property key delimiter.
For my own use, I updated my maven dependency to use commons-configuration version 2.0-SNAPSHOT, and this seems to be fixed. Having looked at the code (PropertiesConfiguration and PropertiesConfigurationLayout), it would not surprise me if it was a bug or a quirk in the commons-lang dependency. Commons-configuration 1.9 uses commons-lang 2.6, but commons-configuration 2.0-SNAPSHOT uses commons-lang3.
The escaping of /
is done to fulfill the requirements of the properties file format. This format is described at the JavaDoc of Properties.load(Reader).
If that's not what you want, then you don't really want a properties file, but some other (possibly similar) format.