Sometimes, We want to include special characters in the value of the properties file. The properties file is a complete feature described below with the example.

  • Inline Comments
  • key and value pair
  • Encoding
  • Unicode
  • Key and value contains spaces
  • Key and value contains special characters which are escaped by backslash

Let’s see a Java properties file example.

# application.properties
# This is one way to write a comment on properties
! this is another way to write a comment on properties
name=john

## key can contain spaces with escape by a backslash
full\ name= john
# value can be spaces
full\ name= john\ Andrew

# Any special characters (:,=,\,@) are escape in key and values
path=c:\\path
name=firstname\:john,lastname\=andrew
support.email=support\\@domain.com
hr\:email=hr\\@domain.com


# unicode
location=\u005ctmp

selectquery= select * from table where id=10

Conclusion

In this post, You learned sample properties file with all features with examples.