Sometimes, We want to include special characters in value of 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 java programmer

  • # symbol
  • = symbol
  • : symbol

escape # sign in properties file

# character can be escaped with \ symbol in properties file

# include special characters

name= first \\# last

How to escape equal sign in 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 properties file. For example, email value

support.email=support\\@domain.com

encoded character we can use %40 in place of @

support.email=support%40domain.com

escape backslash in properties files

For example, storing the path contain backslashes, use double backslashes

temp.location=\\tmp

Replace with backslash with \u005c using encoding character

temp.location=\u005ctmp

When you use escaped characters, In java processor you have to read the processor content with encoding

Conclusion

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