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 and Export

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

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.

Examples

Basic Examples  (6)

Export an association as a Java properties string:

In[1]:=
Click for copyable input
Out[1]=

Create a properties file:

In[1]:=
Click for copyable input

Import it as a Java properties file:

In[2]:=
Click for copyable input
Out[2]=

Create properties file with comments:

In[1]:=
Click for copyable input

Import the data only, as an Association:

In[2]:=
Click for copyable input
Out[2]=

Import the data and the comments:

In[3]:=
Click for copyable input
Out[3]=

Spaces appearing in keys are escaped:

In[1]:=
Click for copyable input
Out[1]=

Values can span on more than one line:

In[1]:=
Click for copyable input
Out[1]=

Special characters are formatted with the hexadecimal notation:

In[1]:=
Click for copyable input
Out[1]=

See Also

"PHPIni"  "Ini"  "CSV"  "TSV"  "Text"  "ApacheLog"

Introduced in 2017
(11.1)