I'm trying to update a properties file with java. The file should be structured like this:
IDs = \
11:22:33:44:55:66:77,\
11:22:33:44:55:66,\
1C:BA:8C:20:C5:0A
But all I get is:
IDs=11\:22\:33\:44\:55\:66\:77\:88,\\\njj\:jj\:jj\:jj\:jj\:jj\:jj\:jj,\\\n55\:55\:55\:55\:55\:55\:55\:55,\\\n
I just couldn't find out a lot about writing properties file with java and I'm completely lost. An other problem is that the ":" is escaped automatically, how can I prevent this? The code I'm using:
String str = "";
for (User u : values){
str = str + u.getId() + ",\\"+"\n";
}
prop.setProperty("IDs", str);
A backslash at the end of a line in a properties file means that the property value continues at the next line. So your property is equivalent to
That's what you should set as the property value. Unfortunately, Properties will never format it on multiple lines as you would like it to be. It will take the backslashes and \n that you store in the property as part of the property value, and will thus escape them. So all you should do is accept for the value to be on a single line, and simply set the property value to
"11:22:33:44:55:66:77,11:22:33:44:55:66,1C:BA:8C:20:C5:0A"
.