.properties explained

Extension:.properties

.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.

Each parameter is stored as a pair of strings, one storing the name of the parameter (called the key), and the other storing the value.

Unlike many popular file formats, there is no RFC for .properties files and specification documents are not always clear, most likely due to the simplicity of the format.

Format

Each line in a .properties file normally stores a single property. Several formats are possible for each line, including key=value, key = value, key:value, and key value. Single-quotes or double-quotes are considered part of the string. Trailing space is significant and presumed to be trimmed as required by the consumer.

Comment lines in .properties files are denoted by the number sign (#) or the exclamation mark (!) as the first non blank character, in which all remaining text on that line is ignored. The backwards slash is used to escape a character. An example of a properties file is provided below.

  1. You are reading a comment in ".properties" file.

! The exclamation mark ('!') can also be used for comments.

  1. Comments are ignored.
  2. Blank lines are also ignored.
  3. Lines with "properties" contain a key and a value separated by a delimiting character.
  4. There are 3 delimiting characters: equal ('='), colon (':') and whitespace (' ', '\t' and '\f').

website = https://en.wikipedia.org/language : Englishtopic .properties files

  1. A word on a line will just create a key with no value.

empty

  1. Whitespace that appears between the key, the delimiter and the value is ignored.
  2. This means that the following are equivalent (other than for readability).

hello=hellohello = hello

  1. To start the value with whitespace, escape it with a backslash ('\').

whitespaceStart = \ <-This space is not ignored.

  1. Keys with the same name will be overwritten by the key that is the furthest in a file.
  2. For example the final value for "duplicateKey" will be "second".

duplicateKey = firstduplicateKey = second

  1. To use the delimiter characters inside a key, you need to escape them with a ('\').
  2. However, there is no need to do this in the value.

delimiterCharacters\:\=\ = This is the value for the key "delimiterCharacters\:\=\ "

  1. Adding a backslash ('\') at the end of a line means that the value continues on the next line.

multiline = This line \continues

  1. If you want your value to include a backslash ('\'), it should be escaped by another backslash ('\').

path = c:\\wiki\\templates

  1. This means that if the number of backslashes ('\') at the end of the line is even, the next line is not included in the value.
  2. In the following example, the value for "evenKey" is "This is on one line\".

evenKey = This is on one line\\

  1. This line is a normal comment and is not included in the value for "evenKey".
  2. If the number of backslash ('\') is odd, then the next line is included in the value.
  3. In the following example, the value for "oddKey" is "This is line one and\# This is line two".

oddKey = This is line one and\\\

  1. This is line two
  2. Whitespace characters at the beginning of a line is removed.
  3. Make sure to add the spaces you need before the backslash ('\') on the first line.
  4. If you add them at the beginning of the next line, they will be removed.
  5. In the following example, the value for "welcome" is "Welcome to Wikipedia!".

welcome = Welcome to \ Wikipedia!

  1. If you need to add newlines and carriage returns, they need to be escaped using ('\n') and ('\r') respectively.
  2. You can also optionally escape tabs with ('\t') for readability purposes.

valueWithEscapes = This is a newline\n and a carriage return\r and a tab\t.

  1. You can also use Unicode escape characters (maximum of four hexadecimal digits).
  2. In the following example, the value for "encodedHelloInJapanese" is "こんにちは".

encodedHelloInJapanese = \u3053\u3093\u306b\u3061\u306f

  1. But with more modern file encodings like UTF-8, you can directly use supported characters.

helloInJapanese = こんにちは

In the example above: