THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1
public StringgetProperty(String key, String defaultElement)

Gets the property element for key. If the key is not found in this object, the
default Properties object (if any) is searched. Returns
defaultElement if the property is not found.

public ObjectsetProperty(String key, String value)

Adds the property key to the map with the given value. This only affects
the Properties object on which it is invokedthe default Properties
object (if any) is unaffected. Returns the previous value that was mapped to
this key, or null if there was none.

public voidstore(OutputStream out, String header)throws
IOException

Saves properties to an OutputStream. This only works if this
Properties object contains only string keys and values (as the
specification says it must); otherwise you get a ClassCastException. If
not null, the header string is written to the output stream as a single-line
comment. Do not use a multiline header string, or else the saved properties
will not be loadable. Only properties in this object are saved to the file; the
default Properties object (if any) is not saved.

public voidload(InputStream in)throws IOException

Loads properties from an InputStream. The property list is presumed to
have been created previously by store. This method puts values into this
Properties object; it does not set values in the default Properties
object.

public Enumeration<?>propertyNames()

Enumerates the keys, including those of any default Properties object.
This method provides a snapshot, and hence can be expensive. The inherited
keys method, by contrast, returns only those properties defined in this object
itself.

public voidlist(PrintWriter out)

Lists (prints) properties on the given PrintWriter. Useful for debugging.

public voidlist(PrintStream out)

Lists (prints) properties on the given PrintStream. Also useful for
debugging.

The default Properties object cannot be changed after the object is created. To change the default
Properties object, you can subclass the Properties class and modify the protected field named
defaults that contains the default Properties object.


Science is facts; just as houses are made of stones, so is science made of facts; but a pile of
stones is not a house and a collection of facts is not necessarily science.
Free download pdf