I try to overwrite existing property value in Properties
file using Properties#setProperty()
method.
But I get an extra backslash...
For example I have following entry inside Properties file:
#url to server
url=http://192.22.222.222
and when I try to overwrite value http://192.22.222.222
by new value http://192.33.333.333
I get followong result:
http\://192.33.333.333
i.e. first backlash is unnecessary. I
Where is problem?
There's no problem. When you load the file again, you won't see a backslash in the property value. The escaping code is choosing to escape all colons (and probably all equals signs) regardless of whether it's strictly required. (When they're not part of the key, you don't have to escape them, but it probably makes the code simpler to do so.)
So long as you're always loading the code using one of the Properties.load
methods, you should see no problems at all.
From the doc:
The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped
'='
,':'
, or white space character other than a line terminator. All of these key termination characters may be included in the key by escaping them with a preceding backslash character; for example,
\:\=
would be the two-character key
":="
.
Java properties will escape some characters like colon when writing a property value. See Properties#store.
This is considered a feature because the Properties format allows colons as key/value separators (see the source of Properties#load method)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With