.properties

.properties
Type of format Configuration Data file
First released 1993?
Developer Sun Microsystems?
Filename extension .properties
Open Format? Yes
Free Format? Yes
Magic Number None

 .properties is a text-based file extension for files mainly used in Java-related technologies to store the configurable parameters of an Java application.

It belongs to java.until package. Properties define the following instance variable. It is similar to an INI file as it's human-readable and easy to edit with a simple text editor. .properties files are often used in BD-J to store configurations for BD-J programs. Some BD-J developers today prefer using XML for more complex configurations.

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.
2.   ! The exclamation mark ('!') can also be used for comments.
3.   # Comments are ignored.
4.   # Blank lines are also ignored.
5.
6.   # Lines with "properties" contain a key and a value separated by a delimiting character.
7.   # There are 3 delimiting characters: equal ('='), colon (':') and whitespace (' ', '\t' and '\f').
8.   website = https://en.wikipedia.org/
9.   language : English
10.  topic .properties files
11.  # A word on a line will just create a key with no value.
12.  empty
13.  # Whitespace that appears between the key, the delimiter and the value is ignored.
14.  # This means that the following are equivalent (other than for readability).
15.  hello=hello
16.  hello = hello
17.  # To start the value with whitespace, escape it with a backspace ('\').
18.  whitespaceStart = \ <-This space is not ignored.
19.  # Keys with the same name will be overwritten by the key that is the furthest in a file.
20.  # For example the final value for "duplicateKey" will be "second".
21.  duplicateKey = first
22.  duplicateKey = second
23.  # To use the delimiter characters inside a key, you need to escape them with a ('\').
24.  # However, there is no need to do this in the value.
25.  delimiterCharacters\:\=\ = This is the value for the key "delimiterCharacters\:\=\ "
26.  # Adding a backslash ('\') at the end of a line means that the value continues on the next line.
27.  multiline = This line \
28.  continues
29.  # If you want your value to include a backslash ('\'), it should be escaped by another backslash ('\').
30.  path = c:\\wiki\\templates
31.  # 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. 
32. # In the following example, the value for "evenKey" is "This is on one line\".
33.  evenKey = This is on one line\\
34.  # This line is a normal comment and is not included in the value for "evenKey".
35.  # If the number of backslash ('\') is odd, then the next line is included in the value.
36.  # In the following example, the value for "oddKey" is "This is line one and\# This is line two".
37.  oddKey = This is line one and\\\
38.  # This is line two
39.  # Whitespace characters at the beginning of a line is removed.
40.  # Make sure to add the spaces you need before the backslash ('\') on the first line. 
41.  # If you add them at the beginning of the next line, they will be removed.
42.  # In the following example, the value for "welcome" is "Welcome to Wikipedia!".
43.  welcome = Welcome to \
44.            Wikipedia!
45.  # If you need to add newlines and carriage returns, they need to be escaped using ('\n') and ('\r') respectively.
46.  # You can also optionally escape tabs with ('\t') for readability purposes.
47.  valueWithEscapes = This is a newline\n and a carriage return\r and a tab\t.
48.  # You can also use Unicode escape characters (maximum of four hexadecimal digits).
49.  # In the following example, the value for "encodedHelloInJapanese" is "ใ“ใ‚“ใซใกใฏ".
50.  encodedHelloInJapanese = \u3053\u3093\u306b\u3061\u306f
51.  # But with more modern file encodings like UTF-8, you can directly use supported characters.
52.  helloInJapanese = ใ“ใ‚“ใซใกใฏ
 

In the example above:

  • the number sign (#) and the exclamation mark (!) at the beginning of a line (line 1, 2, etc), marks text as comments and comments they are ignored,
  • an empty line (line 5) is also ignored,
  • "website" (line 8) would be a key, and its corresponding value would be "https://en.wikipedia.org/",
  • all of the whitespace at the beginning of line 44 is excluded. This means that the key "welcome" (line 43) has the value "Welcome to Wikipedia!" "Welcome to Wikipedia!" and not "Welcome      to Wikipedia!" .

 

 

 


Author(s) : ร† Firestone

on Monday, April 8, 2024 | , , | A comment?
0 responses to “.properties”

Leave a Reply

Popular Pages