Final

java.util
Class Properties

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
All Implemented Interfaces:
Cloneable, Map, Serializable
Direct Known Subclasses:
Provider

public class Properties
extends Hashtable

Properties is a Hashtable where the keys and values must be Strings. Each Properties can have a default Properties which specifies the default values which are used if the key is not in this Properties.

See Also:
Hashtable, System.getProperties(), Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Map
Map.Entry
 
Field Summary
protected  Properties defaults
          The default values for this Properties.
 
Constructor Summary
Properties()
          Constructs a new Properties object.
Properties(Properties properties)
          Constructs a new Properties object using the specified default properties.
 
Method Summary
 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 list(PrintStream out)
          Lists the mappings in this Properties to the specified PrintStream in a human readable form.
 void list(PrintWriter writer)
          Lists the mappings in this Properties to the specified PrintWriter in a human readable form.
 void load(InputStream in)
          Loads properties from the specified InputStream.
 Enumeration propertyNames()
          Answers all of the property names that this Properties contains.
 void save(OutputStream out, String comment)
          Deprecated. Does not throw an IOException, use store()
 Object setProperty(String name, String value)
          Maps the specified key to the specified value.
 void store(OutputStream out, String comment)
          Stores the mappings in this Properties to the specified OutputStream, putting the specified comment at the beginning.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

defaults

protected Properties defaults
The default values for this Properties.

Constructor Detail

Properties

public Properties()
Constructs a new Properties object.


Properties

public Properties(Properties properties)
Constructs a new Properties object using the specified default properties.

Parameters:
properties - the default properties
Method Detail

getProperty

public String getProperty(String name)
Searches for the property with the specified name. If the property is not found, look in the default properties. If the property is not found in the default properties, answer null.

Parameters:
name - the name of the property to find
Returns:
the named property value

getProperty

public String getProperty(String name,
                          String defaultValue)
Searches for the property with the specified name. If the property is not found, look in the default properties. If the property is not found in the default properties, answer the specified default.

Parameters:
name - the name of the property to find
defaultValue - the default value
Returns:
the named property value

list

public void list(PrintStream out)
Lists the mappings in this Properties to the specified PrintStream in a human readable form.

Parameters:
out - the PrintStream

list

public void list(PrintWriter writer)
Lists the mappings in this Properties to the specified PrintWriter in a human readable form.

Parameters:
writer - the PrintWriter

load

public void load(InputStream in)
          throws IOException
Loads properties from the specified InputStream. The properties are of the form key=value, one property per line.

Parameters:
in - the input stream
IOException

propertyNames

public Enumeration propertyNames()
Answers all of the property names that this Properties contains.

Returns:
an Enumeration containing the names of all properties

save

public void save(OutputStream out,
                 String comment)
Deprecated. Does not throw an IOException, use store()

Saves the mappings in this 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() method.

Parameters:
out - the OutputStream
comment - the comment
Throws:
ClassCastException - when the key or value of a mapping is not a String

setProperty

public Object setProperty(String name,
                          String value)
Maps the specified key to the specified value. If the key already exists, the old value is replaced. The key and value cannot be null.

Parameters:
name - the key
value - the value
Returns:
the old value mapped to the key, or null

store

public void store(OutputStream out,
                  String comment)
           throws IOException
Stores the mappings in this 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() method.

Parameters:
out - the OutputStream
comment - the comment
Throws:
ClassCastException - when the key or value of a mapping is not a String
IOException

Final

Licensed Materials - Property of IBM
(C) Copyright IBM Corp. 2006 All Rights Reserved.