Java Properties Tutorial with Example program



Class Properties

All Implemented Interfaces:
    Serializable, Cloneable, Map
    
Direct Known Subclasses:
    Provider

public class Properties
extends Hashtable
{

//
}


Since:
    JDK1.0
    
See Also:
    native2ascii tool for Solaris, native2ascii tool for Windows, Serialized Form
    
Constructors summary

Properties()
    Creates an empty property list with no default values.
    
Properties(Properties defaults)
    Creates an empty property list with the specified defaults.
    

Methods summary

String getProperty(String key)
    Searches for the property with the specified key in this property list.
    
String getProperty(String key, String defaultValue)
    Searches for the property with the specified key in this property list.
    
void list(PrintStream out)
    Prints this property list out to the specified output stream.
    
void list(PrintWriter out)
    Prints this property list out to the specified output stream.
    
void load(InputStream inStream)
    Reads a property list (key and element pairs) from the input byte stream.
    
void load(Reader reader)
    Reads a property list (key and element pairs) from the input character stream in a simple line-oriented format.
    
void loadFromXML(InputStream in)
    Loads all of the properties represented by the XML document on the specified input stream into this properties table.
    
Enumeration propertyNames()
    Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

void save(OutputStream out, String comments)
    Deprecated.
    This method does not throw an IOException if an I/O error occurs while saving the property list. The preferred way to save a properties list is via the store(OutputStream out, String comments) method or the storeToXML(OutputStream os, String comment) method.

Object setProperty(String key, String value)
    Calls the Hashtable method put.
    
void store(OutputStream out, String comments)
    Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the load(InputStream) method.

void store(Writer writer, String comments)
    Writes this property list (key and element pairs) in this Properties table to the output character stream in a format suitable for using the load(Reader) method.

void storeToXML(OutputStream os, String comment)
    Emits an XML document representing all of the properties contained in this table.
    
void storeToXML(OutputStream os, String comment, String encoding)
    Emits an XML document representing all of the properties contained in this table, using the specified encoding.
    
Set stringPropertyNames()
    Returns a set of keys in this property list where the key and its corresponding value are strings, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Methods inherited from class java.util.Hashtable

public void clear()
    Clears this hashtable so that it contains no keys.
    
public boolean contains(Object value)
    Tests if some key maps into the specified value in this hashtable. This operation is more expensive than the containsKey method.
    Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collect

public boolean containsKey(Object key)
    Tests if the specified object is a key in this hashtable.    
      
public boolean containsValue(Object value)
    Returns true if this hashtable maps one or more keys to this value.
    
public Set entrySet()
    Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
    
public V get(Object key)
    Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
    More formally, if this map contains a mapping from a key k to a value v such that (key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)
    
public int hashCode()
    Returns the hash code value for this Map as per the definition in the Map interface.

public boolean isEmpty()
    Tests if this hashtable maps no keys to values.
    
public Enumeration keys()
    Returns an enumeration of the keys in this hashtable.


public Set keySet()
    Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
    
public V put(K key,V value)
    Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null.
    The value can be retrieved by calling the get method with a key that is equal to the original key.
    
public void putAll(Map t)
    Copies all of the mappings from the specified map to this hashtable. These mappings will replace any mappings that this hashtable had for any of the keys currently in the specified map.
    
protected void rehash()
    Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently. This method is called automatically when the number of keys in the hashtable exceeds this hashtable's capacity and load factor.
    
public V remove(Object key)
    Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not in the hashtable.
    
public int size()
    Returns the number of keys in this hashtable
    
public Collection values()

    Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait,clone,hashCode,toString



Related Post

Comments


©candidjava.com