public class Properties extends HashMap<String,String>
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.
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.
Hashtable,
java.lang.System#getPropertiesAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Modifier and Type | Field and Description |
|---|---|
protected Properties |
defaults
The default values for keys not found in this
Properties
instance. |
| Constructor and Description |
|---|
Properties()
Constructs a new
Properties object. |
Properties(Properties properties)
Constructs a new
Properties object using the specified default
Properties. |
| Modifier and Type | Method and Description |
|---|---|
String |
getProperty(String name)
Searches for the property with the specified name.
|
String |
getProperty(String name,
String defaultValue)
Searches for the property with the specified name.
|
void |
load(InputStream in)
Loads properties from the specified
InputStream, assumed to be ISO-8859-1. |
void |
load(Reader in)
Loads properties from the specified
Reader. |
Enumeration<?> |
propertyNames()
Returns all of the property names (keys) in this
Properties object. |
void |
save(OutputStream out,
String comment)
Deprecated.
This method ignores any
IOException thrown while
writing -- use store(java.io.OutputStream, java.lang.String) instead for better exception
handling. |
Object |
setProperty(String name,
String value)
Maps the specified key to the specified value.
|
void |
store(OutputStream out,
String comment)
Stores properties to the specified
OutputStream, using ISO-8859-1. |
void |
store(Writer writer,
String comment)
Stores the mappings in this
Properties object to out,
putting the specified comment at the beginning. |
Set<String> |
stringPropertyNames()
Returns those property names (keys) in this
Properties object for which
both key and value are strings. |
clear, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, valuesequals, hashCode, toStringprotected Properties defaults
Properties
instance.public Properties()
Properties object.public Properties(Properties properties)
Properties object using the specified default
Properties.properties - the default Properties.public String getProperty(String name)
Properties are checked. If the property is not
found in the default Properties, null is returned.name - the name of the property to find.null if it can't be found.public String getProperty(String name, String defaultValue)
Properties. If the property is not
found in the default Properties, it returns the specified
default.name - the name of the property to find.defaultValue - the default value.public void load(InputStream in) throws IOException
InputStream, assumed to be ISO-8859-1.
See "Character Encoding".in - the InputStreamIOExceptionpublic void load(Reader in) throws IOException
Reader.
The properties file is interpreted according to the following rules:
in - the ReaderIOExceptionpublic Enumeration<?> propertyNames()
Properties object.public Set<String> stringPropertyNames()
Properties object for which
both key and value are strings.@Deprecated public void save(OutputStream out, String comment)
IOException thrown while
writing -- use store(java.io.OutputStream, java.lang.String) 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.out - the OutputStream to write to.comment - the comment to add at the beginning.ClassCastException - if the key or value of a mapping is not a
String.public Object setProperty(String name, String value)
null.name - the key.value - the value.null.public void store(OutputStream out, String comment) throws IOException
OutputStream, using ISO-8859-1.
See "Character Encoding".out - the OutputStreamcomment - an optional comment to be written, or nullIOExceptionClassCastException - if a key or value is not a stringpublic void store(Writer writer, String comment) throws IOException
Properties object to out,
putting the specified comment at the beginning.writer - the Writercomment - an optional comment to be written, or nullIOExceptionClassCastException - if a key or value is not a string