Properties Class

suggest change

Introduction

The properties object contains key and value pair both as a string. The java.util.Properties class is the subclass of Hashtable.

It can be used to get property value based on the property key. The Properties class provides methods to get data from properties file and store data into properties file. Moreover, it can be used to get properties of system.

Advantage of properties file

Recompilation is not required, if information is changed from properties file: If any information is changed from

Syntax

comment

Remarks

A Properties object is a Map whose keys and values are Strings by convention. Although the methods of Map can be used to access the data, the more type-safe methods getProperty, setProperty, and stringPropertyNames are usually used instead.

Properties are frequently stored in Java property files, which are simple text files. Their format is documented thoroughly in the Properties.load method. In summary:

Most frameworks, including Java SE’s own facilities like java.util.ResourceBundle, load property files as InputStreams. When loading a property file from an InputStream, that file is may only contain ISO 8859-1 characters (that is, characters in the 0–255 range). Any other characters must be represented as \u escapes. However, you can write a text file in any encoding and use the native2ascii tool (which comes with every JDK) to do that escaping for you.

If you are loading a property file with your own code, it can be in any encoding, as long as you create a Reader (such as an InputStreamReader) based on the corresponding Charset. You can then load the file using load(Reader) instead of the legacy load(InputStream) method.

You can also store properties in a simple XML file, which allows the file itself to define the encoding. Such a file can be loaded with the loadFromXML method. The DTD describing the structure of such XML files is located at http://java.sun.com/dtd/properties.dtd .

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Properties Class:
* Properties Class

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
42 Properties Class
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap