FilePropertiespublic class FileProperties extends Properties The FileProperties class extends Properties ,
"a persistent set of properties [that] can be saved to a stream
or loaded from a stream". This subclass attends to all the mundane
details of opening the Stream(s) for actually saving and loading
the Properties.
This subclass preserves the useful feature that
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 Summary |
---|
protected String | fileName | protected InputStream | inStrThe InputStream for loading | protected OutputStream | outStrThe OutputStream for loading |
Constructors Summary |
---|
public FileProperties(String loadsaveFileName)Construct a FileProperties given a fileName.
super();
fileName = loadsaveFileName;
load();
| public FileProperties(String loadsaveFileName, Properties defProp)Construct a FileProperties given a fileName and
a list of default properties.
super(defProp);
fileName = loadsaveFileName;
load();
|
Methods Summary |
---|
public void | close()
try {
if (inStr != null)
inStr.close();
if (outStr != null)
outStr.close();
} catch (IOException e) {
// don't care
}
| public void | load()Load the properties from the saved filename.
If that fails, try again, tacking on the .properties extension
try {
if (inStr==null) {
inStr = new FileInputStream(fileName);
}
} catch (FileNotFoundException fnf) {
if (!fileName.endsWith(".properties")) {
inStr = new FileInputStream(fileName + ".properties");
// If we succeeded, remember it:
fileName += ".properties";
} else
// It did end with .properties and failed, re-throw exception.
throw fnf;
}
// now message the superclass code to load the file.
load(inStr);
| public void | save()Save the properties for later loading.
if (outStr==null) {
outStr = new FileOutputStream(fileName);
}
// Get the superclass to do most of the work for us.
store(outStr, "# Written by FileProperties.save() at " + new Date());
|
|