java.util.Properties
java.util.Hashtable
None
None
JDK 1.0 or later
The Properties class is a subclass of Hashtable that deals exclusively with string keys and string values. Furthermore, a Properties object can be written to an OutputStream and read from an InputStream. Note that the load() and save() correctly convert Unicode strings to and from byte streams, using the getLocalizedInputStream() and getLocalizedOutputStream() methods of Runtime.
public class java.util.Properties extends java.util.Hashtable { // Variables protected Properties defaults; // Constructors public Properties(); public Properties(Properties defaults); // Instance Methods public String getProperty(String key); public String getProperty(String key, String defaultValue); public void list(PrintStream out); public void list(PrintWriter out); // New in 1.1 public synchronized void load(InputStream in); public Enumeration propertyNames(); public synchronized void save(OutputStream out, String header); }
A collection of default property values. If a key/value pair is not found in this Properties object, the defaults object is searched.
This constructor creates an empty Properties object.
A set of default key/value pairs.
This constructor creates an empty Properties object that gets default values for keys that it does not contain from the given Properties object.
The key of the value to retrieve.
The value of the given property or null if the key is not associated with any value.
This method returns the value that is associated with the given key. If the key is not found, a default value is returned if this object was created with a default Properties table that contains a value for the key. If neither a value nor a default value can be found, this method returns null.
The key of the value to retrieve.
The value to return if key cannot be found.
The value of the given property or defaultValue if the key is not associated with any value.
This method returns the value that is associated with the given key. If the key is not found, a default value is returned if this object was created with a default Properties table that contains a value for the key. If neither a value nor a default value can be found, this method returns defaultValue.
The output stream to use.
This method writes a listing of the contents of this object, in a format suitable for debugging, to the given PrintStream. As of JDK 1.1, use list(PrintWriter) instead.
New as of JDK 1.1
The output stream to use.
This method writes a listing of the contents of this object, in a format suitable for debugging, to the given PrintWriter.
The input stream to use.
If any kind of I/O error occurs.
This method reads key/value pairs from the given InputStream. Here is the format the method expects:
key = value
or
key : value
or
key value
All of these forms are equivalent. The method also recognizes the following escape characters and treats them as described:
Character |
Treatment |
---|---|
\newline |
An escaped newline character is ignored, along with the spaces or tabs that follow it |
\n |
Expands to a newline character |
\r |
Expands to a return character |
\t |
Expands to a tab character |
\uxxxx |
Expands to the Unicode character code specified by the hexadecimal digits |
The keys in this Properties object as an Enumeration.
This method returns an Enumeration that iterates through the keys in this Properties object.
The output stream to use.
A header string.
This method writes key/value pairs to the given OutputStream. The format of the output is such that it can be read by the load() method.
If header is not null, a # followed by header is written to the OutputStream first, thereby making the content of the string a comment that precedes the key/value pairs.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clear() |
Hashtable |
clone() |
Hashtable |
contains(Object) |
Hashtable |
containsKey(Object) |
Hashtable |
elements() |
Hashtable |
equals(Object) |
Object |
finalize() |
Object |
get(Object) |
Hashtable |
getClass() |
Object |
hashCode() |
Object |
isEmpty() |
Hashtable |
keys() |
Hashtable |
notify() |
Object |
notifyAll() |
Object |
put(Object, Object) |
Hashtable |
remove(Object) |
Hashtable |
size() |
Hashtable |
toString() |
Hashtable |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
Enumeration, Hashtable, InputStream, IOException, OutputStream, PrintStream, PrintWriter, Runtime