public class Properties
ImplementsMap<String, String>
A Properties object is a Hashtable where the keys and values
must be Strings. Each property can have a default
Properties list which specifies the default
values to be used when a given key is not found in this Properties
instance.
Character Encoding
Note that in some cases Properties uses ISO-8859-1 instead of UTF-8.
ISO-8859-1 is only capable of representing a tiny subset of Unicode.
Use either the loadFromXML/storeToXML methods (which use UTF-8 by
default) or the load/store overloads that take
an OutputStreamWriter (so you can supply a UTF-8 instance) instead.
See also
Hashtablejava.lang.System#getProperties
Fields
protected Properties defaults | The default values for keys not found in this Properties instance. |
Constructors
public Properties() | Constructs a new Properties object. |
public Properties(Properties properties) | Constructs a new Properties object using the specified default Properties. |
Methods
Inherited nested types
Inherited methods
From HashMap
clear, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
From AbstractMap
Field details
defaults
protected Properties defaultsProperties
instance.Constructor details
Properties
public Properties()Properties object.Properties
public Properties(Properties properties)Properties object using the specified default
Properties.Parameters
propertiesProperties- the default
Properties.
Method details
getProperty
public String getProperty(String name)Properties are checked. If the property is not
found in the default Properties, null is returned.Parameters
nameString- the name of the property to find.
Returns
null if it can’t be found.getProperty
public String getProperty(String name, String defaultValue)Properties. If the property is not
found in the default Properties, it returns the specified
default.Parameters
nameString- the name of the property to find.
defaultValueString- the default value.
Returns
load
public synchronized void load(InputStream in)
throws IOExceptionInputStream, assumed to be ISO-8859-1.
See “Character Encoding”.Parameters
inInputStream- the
InputStream
Throws
load
public synchronized void load(Reader in)
throws IOExceptionLoads properties from the specified Reader.
The properties file is interpreted according to the following rules:
Empty lines are ignored.
Lines starting with either a “#” or a “!” are comment lines and are ignored.
A backslash at the end of the line escapes the following newline character ("\r", “\n”, “\r\n”). If there’s whitespace after the backslash it will just escape that whitespace instead of concatenating the lines. This does not apply to comment lines.
A property line consists of the key, the space between the key and the value, and the value. The key goes up to the first whitespace, “=” or “:” that is not escaped. The space between the key and the value contains either one whitespace, one “=” or one “:” and any amount of additional whitespace before and after that character. The value starts with the first character after the space between the key and the value.
Following escape sequences are recognized:
\,\\,\r,\n,\!,\#,\t,\b,\f, and(unicode character).
Parameters
inReader- the
Reader
Throws
propertyNames
public Enumeration<?> propertyNames()Properties object.stringPropertyNames
public Set<String> stringPropertyNames()Properties object for which
both key and value are strings.Returns
save
public void save(OutputStream out, String comment)IOException thrown while
writing – use #store instead for better exception
handling.Properties to the specified OutputStream, putting the specified comment at the beginning. The output
from this method is suitable for being read by the
#load(InputStream) method.Parameters
outOutputStream- the
OutputStreamto write to. commentString- the comment to add at the beginning.
Throws
ClassCastException- if the key or value of a mapping is not a String.
setProperty
public Object setProperty(String name, String value)null.Parameters
nameString- the key.
valueString- the value.
Returns
null.store
public synchronized void store(OutputStream out, String comment)
throws IOExceptionOutputStream, using ISO-8859-1.
See “Character Encoding”.Parameters
outOutputStream- the
OutputStream commentString- an optional comment to be written, or null
Throws
IOExceptionClassCastException- if a key or value is not a string
store
public synchronized void store(Writer writer, String comment)
throws IOExceptionProperties object to out,
putting the specified comment at the beginning.Parameters
writerWriter- the
Writer commentString- an optional comment to be written, or null
Throws
IOExceptionClassCastException- if a key or value is not a string