0

Hi this post is related to my old post. But in this I have achieved much. I am using FileBasedConfigurationBuilder class of Apache common configuration API for updating property file in java. Below is my code:

FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(
                PropertiesConfiguration.class)
                        .configure(new Parameters().properties().setFileName("test.properties")
                                .setThrowExceptionOnMissing(true));
PropertiesConfiguration config = builder.getConfiguration();
config.setProperty("Id", "3");
builder.save();
System.out.println("config.properties updated Successfully!!");

Now one of my key have value like C\://ABC.net\\:1010. After modification it becomes C\\://ABC.net\\:1010. Means it single backslash is converting to two single backslash. Previously I was using common configuration jar 1.10 it that forwardslash also getting change. Now I have used common configuration version commons-configuration2-2.0.jar. By this version only problem in backslash.

Can any one suggested how to avoid this? I need that after modification single backslash should not convert to doublebackslash.Please note that I don't want to change the property file.

I was following below post to reach till here. PropertiesConfiguration - Using "/" in Property value

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
amitabh pandey
  • 65
  • 1
  • 11

1 Answers1

0

In a properties file, the : character is escaped with a single backslash, which is what seems to be happening in your question.

See this question How do you escape colon (:) in Properties file?

which points to the Properties documentation

ptomli
  • 11,730
  • 4
  • 40
  • 68
  • My Properties file has always value with escape character.C\:ABC.net.But after modification it becomes C\\:ABC.net.I am not modifying this key.I am modifying some other key but this is also changing.I need to prevent this. – amitabh pandey May 08 '18 at 11:23