Sometimes, We want to include special characters in the value of the properties file.
Let’s see some examples
# include special characters selectquery= select * from table where id=10
We can include below special characters to escape and read by a java programmer
- # symbol
- = symbol
- : symbol
escape # sign in the properties file
# character can be escaped with \ symbol in the properties file
# include special characters name= first \\# last
How to escape equal sign in a properties file
Here is an example
# include special characters selectquery= select * from table where id`\=`10
The same can be escaped with java Unicode characters equal sign can be replaced with java Unicode \u003d value and white space for \u0020
# include special characters selectquery=\u0020select\u0020*\u0020from\u0020table\u0020where\u0020id\u003d10
escape @ character in properties file
some times, We want to escape @ character in a properties file. For example, email value
an encoded character we can use %40 in place of @
escape backslash in properties files
For example, storing the path containing backslashes, use double backslashes
Replace with backslash with \u005c using encoding character
When you use escaped characters, In java processor you have to read the processor content with encoding
You learned many ways to use escape and special characters in properties.
You can use different ways or Unicode characters. Unicode characters are less readable.