Packages  This Package  Prev  Next  Index  

§3.6 Class Properties

public  class  java.util.Properties
    extends  java.util.Hashtable  (I-§3.4)
{
        // Fields
    protected Properties defaults;	§3.6.1

        // Constructors
    public Properties();	§3.6.2
    public Properties(Properties  defaults);	§3.6.3

        // Methods
    public String getProperty(String  key);	§3.6.4
    public String getProperty(String  key, String  defaultValue); §3.6.5
    public void list(PrintStream  out);	§3.6.6
    public void load(InputStream  in);	§3.6.7
    public Enumeration propertyNames();	§3.6.8
    public void save(OutputStream  out, String  header);	§3.6.9
}
The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and 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.


Fields

defaults

protected Properties defaults
A property list which contains contains default values for any keys not found in this property list.

Constructors

Properties

public Properties()
Creates an empty property list with no default values.

Properties

public Properties(Properties defaults)
Creates an empty property list with the specified defaults.
Parameters:
defaults - the defaults

Methods

getProperty

public String getProperty(String key)
Searches for the property with the specified key in this property list.
Parameters:
key - the property key
Returns:
the value in this property list with the specified key value. If the key is not found in this property list, the default property list (I-§3.6.1), and its defaults, recursively, are then checked. The method returns null if the property is not found.

getProperty

public String getProperty(String key, String defaultValue)
Searches for the property with the specified key in this property list.
Parameters:
key - the hashtable key
defaultValue - a default value
Returns:
the value in this property list with the specified key value. If the key is not found in this property list, the default property list (I-§3.6.1), and its defaults, recursively, are then checked. The method returns the default value argument if the property is not found.

list

public void list(PrintStream out)
Prints this property list out to the specified output stream. This method is useful for debugging.
Parameters:
out - an output stream

load

public void load(InputStream in) throws IOException
Reads a property list from an input stream.
Parameters:
in - the input stream
Throws
IOException (I-§2.29)
If an error occurred when reading from the input stream.

propertyNames

public Enumeration propertyNames()
Returns:
An enumeration (I-§3.11) of all the keys in this property list, including the keys in the default property list (I-§3.6.1).

save

public void save(OutputStream out, String header)
Stores this property list to the specified output stream. The string header is printed as a comment at the beginning of the stream.
Parameters:
out - an output stream
header - a description of the property list

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com