.properties

Last updated
.properties
Filename extension
.properties
Internet media type text/plain

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

Contents

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.

# You are reading a comment in ".properties" file.! The exclamation mark ('!') can also be used for comments.# Comments are ignored.# Blank lines are also ignored.# Lines with "properties" contain a key and a value separated by a delimiting character.# There are 3 delimiting characters: equal ('='), colon (':') and whitespace (' ', '\t' and '\f').website=https://en.wikipedia.org/language:Englishtopic.properties files# A word on a line will just create a key with no value.empty# Whitespace that appears between the key, the delimiter and the value is ignored.# This means that the following are equivalent (other than for readability).hello=hellohello=hello# To start the value with whitespace, escape it with a backslash ('\').whitespaceStart=\ <-This space is not ignored.# Keys with the same name will be overwritten by the key that is the furthest in a file.# For example the final value for "duplicateKey" will be "second".duplicateKey=firstduplicateKey=second# To use the delimiter characters inside a key, you need to escape them with a ('\').# However, there is no need to do this in the value.delimiterCharacters\:\=\ =This is the value for the key "delimiterCharacters\:\=\ "# Adding a backslash ('\') at the end of a line means that the value continues on the next line.multiline=This line \continues# If you want your value to include a backslash ('\'), it should be escaped by another backslash ('\').path=c:\\wiki\\templates# 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. # In the following example, the value for "evenKey" is "This is on one line\".evenKey=This is on one line\\# This line is a normal comment and is not included in the value for "evenKey".# If the number of backslash ('\') is odd, then the next line is included in the value.# In the following example, the value for "oddKey" is "This is line one and\# This is line two".oddKey=This is line one and\\\# This is line two# Whitespace characters at the beginning of a line is removed.# Make sure to add the spaces you need before the backslash ('\') on the first line. # If you add them at the beginning of the next line, they will be removed.# In the following example, the value for "welcome" is "Welcome to Wikipedia!".welcome=Welcome to \Wikipedia!# If you need to add newlines and carriage returns, they need to be escaped using ('\n') and ('\r') respectively.# 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.# You can also use Unicode escape characters (maximum of four hexadecimal digits).# In the following example, the value for "encodedHelloInJapanese" is "こんにちは".encodedHelloInJapanese=\u3053\u3093\u306b\u3061\u306f# But with more modern file encodings like UTF-8, you can directly use supported characters.helloInJapanese=こんにちは

In the example above:

Before Java 9, the encoding of a .properties file is ISO-8859-1, also known as Latin-1. All non-ASCII characters must be entered by using Unicode escape characters, e.g. \uHHHH where HHHH is a hexadecimal index of the character in the Unicode character set. This allows for using .properties files as resource bundles for localization. A non-Latin-1 text file can be converted to a correct .properties file by using the native2ascii tool that is shipped with the JDK or by using a tool, such as po2prop, [1] that manages the transformation from a bilingual localization format into .properties escaping.

An alternative to using unicode escape characters for non-Latin-1 character in ISO 8859-1 character encoded Java *.properties files is to use the JDK's XML Properties file format which by default is UTF-8 encoded, introduced starting with Java 1.5. [2]

Another alternative is to create custom control that provides custom encoding. [3]

In Java 9 and newer, the default encoding specifically for property resource bundles is UTF-8, and if an invalid UTF-8 byte sequence is encountered it falls back to ISO-8859-1. [4] [5]

Editing

Editing .properties files is done using any text editor such as those typically installed on various Operating Systems including Notepad on Windows or Emacs, Vim, etc. on Linux systems.

Third-party tools are also available with additional functionality specific to editing .properties files such as:

Non-Java uses and exceptions

Apache Flex uses .properties files as well, but here they are UTF-8 encoded. [6]

In Apache mod_jk's uriworkermap.properties format, an exclamation mark ("!") denotes a Negation operator when used as the first non blank character in a line. [7]

Perl CPAN contains Config::Properties to interface to a .properties file. [8]

SAP uses .properties files for localization within their framework SAPUI5 and its open-source variant OpenUI5 [9]

There are many Node.js (JavaScript/TypeScript) options available on Npm's package manager. [10]

PHP also has many package options available. [11]

See also

Related Research Articles

<span class="mw-page-title-main">Plain text</span> Term for computer data consisting only of unformatted characters of readable material

In computing, plain text is a loose term for data that represent only characters of readable material but not its graphical representation nor other objects. It may also include a limited number of "whitespace" characters that affect simple arrangement of text, such as spaces, line breaks, or tabulation characters. Plain text is different from formatted text, where style information is included; from structured text, where structural parts of the document such as paragraphs, sections, and the like are identified; and from binary files in which some portions must be interpreted as binary objects.

<span class="mw-page-title-main">XML</span> Markup language by the W3C for encoding of data

Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The World Wide Web Consortium's XML 1.0 Specification of 1998 and several other related specifications—all of them free open standards—define XML.

In computing and telecommunication, an escape character is a character that invokes an alternative interpretation on the following characters in a character sequence. An escape character is a particular case of metacharacters. Generally, the judgement of whether something is an escape character or not depends on the context.

In computing, the Java API for XML Processing (JAXP), one of the Java XML application programming interfaces (APIs), provides the capability of validating and parsing XML documents. It has three basic parsing interfaces:

In computer science, an escape sequence is a combination of characters that has a meaning other than the literal characters contained therein; it is marked by one or more preceding characters.

A string literal or anonymous string is a literal for a string value in the source code of a computer program. Modern programming languages commonly use a quoted sequence of characters, formally "bracketed delimiters", as in, where is a string literal with value. Methods such as escape sequences can be used to avoid the problem of delimiter collision and allow the delimiters to be embedded in a string. There are many alternate notations for specifying string literals especially in complicated cases. The exact notation depends on the programming language in question. Nevertheless, there are general guidelines that most modern programming languages follow.

In computer programming, Base64 is a group of binary-to-text encoding schemes that transforms binary data into a sequence of printable characters, limited to a set of 64 unique characters. More specifically, the source binary data is taken 6 bits at a time, then this group of 6 bits is mapped to one of 64 unique characters.

<span class="mw-page-title-main">JAR (file format)</span> Java archive file format

A JAR file is a package file format typically used to aggregate many Java class files and associated metadata and resources into one file for distribution.

YAML is a human-readable data serialization language. It is commonly used for configuration files and in applications where data are being stored or transmitted. YAML targets many of the same communications applications as Extensible Markup Language (XML) but has a minimal syntax that intentionally differs from Standard Generalized Markup Language (SGML). It uses Python-style indentation to indicate nesting and does not require quotes around most string values.

<span class="mw-page-title-main">Comma-separated values</span> File format used to store data

Comma-separated values (CSV) is a text file format that uses commas to separate values, and newlines to separate records. A CSV file stores tabular data in plain text, where each line of the file typically represents one data record. Each record consists of the same number of fields, and these are separated by commas in the CSV file. If the field delimiter itself may appear within a field, fields can be surrounded with quotation marks.

<span class="mw-page-title-main">Delimiter</span> Characters that specify the boundary between regions in a data stream

A delimiter is a sequence of one or more characters for specifying the boundary between separate, independent regions in plain text, mathematical expressions or other data streams. An example of a delimiter is the comma character, which acts as a field delimiter in a sequence of comma-separated values. Another example of a delimiter is the time gap used to separate letters and words in the transmission of Morse code.

In computer science, canonicalization is a process for converting data that has more than one possible representation into a "standard", "normal", or canonical form. This can be done to compare different representations for equivalence, to count the number of distinct data structures, to improve the efficiency of various algorithms by eliminating repeated calculations, or to make it possible to impose a meaningful sorting order.

The data URI scheme is a uniform resource identifier (URI) scheme that provides a way to include data in-line in Web pages as if they were external resources. It is a form of file literal or here document. This technique allows normally separate elements such as images and style sheets to be fetched in a single Hypertext Transfer Protocol (HTTP) request, which may be more efficient than multiple HTTP requests, and used by several browser extensions to package images as well as other multimedia content in a single HTML file for page saving. As of 2024, data URIs are fully supported by all major browsers.

<span class="mw-page-title-main">JSON</span> Open standard file format and data interchange

JSON is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays. It is a commonly used data format with diverse uses in electronic data interchange, including that of web applications with servers.

An INI file is a configuration file for computer software that consists of a text-based content with a structure and syntax comprising key–value pairs for properties, and sections that organize the properties. The name of these configuration files comes from the filename extension INI, for initialization, used in the MS-DOS operating system which popularized this method of software configuration. The format has become an informal standard in many contexts of configuration, but many applications on other operating systems use different file name extensions, such as conf and cfg.

<span class="mw-page-title-main">Comment (computer programming)</span> Explanatory note in the source code of a computer program

In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters. The syntax of comments in various programming languages varies considerably.

XPath is an expression language designed to support the query or transformation of XML documents. It was defined by the World Wide Web Consortium (W3C) in 1999, and can be used to compute values from the content of an XML document. Support for XPath exists in applications that support XML, such as web browsers, and many programming languages.

Apache Click is a page and component oriented web application framework for the Java language and is built on top of the Java Servlet API.

In the C programming language, an escape sequence is specially delimited text in a character or string literal that represents one or more other characters to the compiler. It allows a programmer to specify characters that are otherwise difficult or impossible to specify in a literal.

Fielded Text is a proposed standard which provides structure and schema definition to text files which contain tables of values. The standard allows the format and structure of the data within the text file to be specified by a Meta file. This Meta file can then be used to access the data in the file in manner similar to which data is accessed in a database.

References

  1. Translate Toolkit's po2prop converts native character encodings in a Gettext PO file into correctly escaped ascii without the need for native2ascii
  2. Java XML Properties DTD
  3. "java - How to use UTF-8 in resource properties with ResourceBundle". Stack Overflow . Archived from the original on 2015-03-17. Retrieved 2015-01-28.
  4. "Internationalization Enhancements in JDK 9". Oracle Help Center. Retrieved 2018-01-05.
  5. "JEP 226: UTF-8 Property Resource Bundles". OpenJDK. Retrieved 2020-09-03.
  6. "IResourceBundle". Adobe ActionScript 3 (AS3 Flex) API Reference.
  7. "uriworkermap.properties configuration". The Apache Tomcat Connectors - Reference Guide.
  8. "Config::Properties - Read and write property files". metacpan.org.
  9. "SAPUI5 SDK - Demo Kit". sapui5.hana.ondemand.com. Retrieved 2019-05-14.
  10. "keywords:properties java parse - npm search". www.npmjs.com. Retrieved 2022-03-22.
  11. "Packagist". packagist.org. Retrieved 2022-03-22.