JavaProperties (.properties)

Background & Context

    • Configuration file format.
    • Commonly used in Java projects.
    • Associates string keys to string values.
    • Plain text format.
    • Uses ISO Latin-1 character encoding.

Import & Export

  • Import[""] returns a representation of a properties file as an Association.
  • Import["file","JavaProperties"] returns a representation of a file as a properties file.
  • Import["",elem] returns the specified data representation of a properties file.
  • Import["file",{"JavaProperties",elem}] returns the specified data representation of a file.
  • Export["",expr] exports expr as a Java property file.

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties and settings
  • Data representation elements:
  • "Data"data as an association
    "DataRules"data as a list of rules
    "CommentedData"data as a list of sections as rules, and comments as strings
  • The "JavaProperties" format exports elements of an association or a list.
  • "JavaProperties" treats an association as a list of properties. Keys and values are converted to strings using InputForm.
  • "JavaProperties" accepts lists containing a mixture of rules and strings. Rules are exported as properties; strings are exported as commented lines.
  • "JavaProperties" uses "ISOLatin1" (or "ISO8859-1") character encoding.
  • Unicode codepoints outside the ISO Latin-1 range are represented as "\uNNNN", where NNNN is the four-digit hexadecimal representation of the codepoint value.
  • A commented line starts with "!" or "#".
  • Values can span multiple lines. Each continuation line must end with a non-commented \.
  • The characters #, :, =, !, \, \t and \f are escaped with a preceding \.
  • Spaces are escaped when encountered in a key.
  • Newline characters are escaped when encountered in a value.


Basic Examples  (6)

Export an association as a Java properties string:

Create a properties file:

Import it as a Java properties file:

Create properties file with comments:

Import the data only, as an Association:

Import the data and the comments:

Spaces appearing in keys are escaped:

Values can span on more than one line:

Special characters are formatted with the hexadecimal notation:

Introduced in 2017