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 | fileNameThe name of the file this FileProperties represents. | private boolean | existsTrue if the file represented by fileName exists |
Constructors Summary |
---|
public FileProperties(String loadsaveFileName)Construct a FileProperties given a fileName.
super();
setFileName(loadsaveFileName);
load();
| public FileProperties(String loadsaveFileName, Properties defProp)Construct a FileProperties given a fileName and
a list of default properties.
super(defProp);
setFileName(loadsaveFileName);
load();
|
Methods Summary |
---|
public void | close()No longer needed.
// Nothing to do
| public java.lang.String | getFileName()
return fileName;
| public java.util.Properties | load()Load the properties from the saved filename.
If that fails, try again, tacking on the .properties extension
if (!exists)
return this;
// Sorry it's an InputStream not a Reader, but that's what
// the superclass load method still requires (as of 1.4 at least).
InputStream inStr = new FileInputStream(fileName);
// now message the superclass code to load the file.
load(inStr);
inStr.close();
// Return "this" for convenience
return this;
| public void | save()Save the properties to disk for later loading.
OutputStream outStr = new FileOutputStream(fileName);
// Get the superclass to do most of the work for us.
store(outStr, "# Written by FileProperties.save() at " + new Date());
outStr.close();
| void | setFileName(java.lang.String newName)Set the fileName. If it exists not, but it+".properties" does,
save the full name.
fileName = newName;
if (new File(fileName).exists()) {
exists = true;
return;
}
if (!newName.endsWith(".properties")) {
File f2 = new File(newName + ".properties");
if (f2.exists()) {
exists = true;
fileName = newName + ".properties";
return;
}
}
|
|