public class Properties extends Hashtable<Object,Object>
Properties
class represents a persistent set of
properties. The Properties
can be saved to a stream
or loaded from a stream. Each key and its corresponding value in
the property list is a string.
A property list can contain another property list as its "defaults"; this second property list is searched if the property key is not found in the original property list.
Because Properties
inherits from Hashtable
, the
put
and putAll
methods can be applied to a
Properties
object. Their use is strongly discouraged as they
allow the caller to insert entries whose keys or values are not
Strings
. The setProperty
method should be used
instead. If the store
or save
method is called
on a "compromised" Properties
object that contains a
non-String
key or value, the call will fail. Similarly,
the call to the propertyNames
or list
method
will fail if it is called on a "compromised" Properties
object that contains a non-String
key.
The load(Reader)
/
store(Writer, String)
methods load and store properties from and to a character based stream
in a simple line-oriented format specified below.
The load(InputStream)
/
store(OutputStream, String)
methods work the same way as the load(Reader)/store(Writer, String) pair, except
the input/output stream is encoded in ISO 8859-1 character encoding.
Characters that cannot be directly represented in this encoding can be written using
Unicode escapes as defined in section 3.3 of
The Java™ Language Specification;
only a single 'u' character is allowed in an escape
sequence. The native2ascii tool can be used to convert property files to and
from other character encodings.
Properties object without the need for external synchronization.
Constructor and Description |
---|
Properties()
Creates an empty property list with no default values.
|
Modifier and Type | Method and Description |
---|---|
void |
load(InputStream inStream)
Reads a property list (key and element pairs) from the input
byte stream.
|
public Properties()
public void load(InputStream inStream) throws IOException
load(Reader)
and is assumed to use
the ISO 8859-1 character encoding; that is each byte is one Latin1
character. Characters not in Latin1, and certain special characters,
are represented in keys and elements using Unicode escapes as defined in
section 3.3 of
The Java™ Language Specification.
The specified stream remains open after this method returns.
inStream
- the input stream.IOException
- if an error occurred when reading from the
input stream.IllegalArgumentException
- if the input stream contains a
malformed Unicode escape sequence.