Class Properties

All Implemented Interfaces:
Map<Object,Object>

public class Properties extends Hashtable<Object,Object>

String keys and values, a second table of defaults behind them, and the .properties text format.

The format is read as the JDK reads it: # and ! comments, =, : or white space between key and value, a trailing backslash continuing a line (the next line's indentation dropped), and the escapes \t, \n, \r, \f and backslash-u followed by four hexadecimal digits; a backslash before any other character stands for that character. A stream is ISO 8859-1; a reader is whatever its characters are. store(OutputStream, String) writes text that load(InputStream) reads back to the same table, escaping what the format requires and, on a stream, every character outside printable ASCII.

The XML form (loadFromXML, storeToXML) and list are not provided.

  • Field Details

    • defaults

      protected Properties defaults
      The table consulted for a key this one does not have, or null.
  • Constructor Details

    • Properties

      public Properties()
      An empty table with no defaults.
    • Properties

      public Properties(Properties defaults)
      An empty table with defaults behind it.
  • Method Details

    • getProperty

      public String getProperty(String name)
      The value for name here, else in the defaults, else null. A value that is not a String counts as absent, as in the JDK.
    • getProperty

      public String getProperty(String name, String defaultValue)
      The value for name as getProperty(String) finds it, or defaultValue when there is none.
    • setProperty

      public Object setProperty(String name, String value)
      Maps name to value in this table, answering the value it replaced.
    • load

      public void load(InputStream in) throws IOException
      Reads ISO 8859-1 .properties text, adding to what is here. The stream is left open.
      Throws:
      IOException
    • load

      public void load(Reader in) throws IOException
      Reads .properties text, adding to what is here. The reader is left open.
      Throws:
      IOException
    • propertyNames

      public Enumeration<?> propertyNames()
      Every key of this table and of its defaults.
    • stringPropertyNames

      public Set<String> stringPropertyNames()
      The keys, of this table and of its defaults, whose key and value are both strings.
    • save

      @Deprecated public void save(OutputStream out, String comments)
      Deprecated.

      Writes this table as store(OutputStream, String) does, ignoring any IOException.

      Deprecated

      An error writing is lost; use store(OutputStream, String).

    • store

      public void store(OutputStream out, String comments) throws IOException

      Writes this table (not its defaults) as ISO 8859-1 .properties text: the comment lines, a line with the current date, then one key=value line per entry. The stream is flushed and left open.

      Throws
      • ClassCastException: if a key or value is not a String
      Throws:
      IOException
    • store

      public void store(Writer writer, String comments) throws IOException

      Writes this table as .properties text, leaving characters outside ASCII as they are. The writer is flushed and left open.

      Throws
      • ClassCastException: if a key or value is not a String
      Throws:
      IOException