How can I escape the equals sign (=
) in Java property files? I would like to put something as the following in my file:
table.whereclause=where id=100
In my case, two leading '\\' working fine for me.
If you have an equals sign in your value, you'll need to escape it with a backslash unless you've quoted the entire string.
In addition to properties and blank lines, the application. properties field may contain comments. To comment a line, just put the hash character at the beginning of a line.
properties is a file extension for files mainly used in Java-related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.
In your specific example you don't need to escape the equals - you only need to escape it if it's part of the key. The properties file format will treat all characters after the first unescaped equals as part of the value.
Moreover, Please refer to load(Reader reader) method from Property
class on javadoc
In load(Reader reader)
method documentation it says
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
":=".
Line terminator characters can be included using\r
and\n
escape sequences. Any white space after the key is skipped; if the first non-white space character after the key is'='
or':'
, then it is ignored and any white space characters after it are also skipped. All remaining characters on the line become part of the associated element string; if there are no remaining characters, the element is the empty string""
. Once the raw character sequences constituting the key and element are identified, escape processing is performed as described above.
Hope that helps.
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