FileDocCategorySizeDatePackage
FileProperties.javaAPI DocExample2823Sun Mar 07 11:14:56 GMT 2004com.darwinsys.util

FileProperties

public 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.

author
Ian F. Darwin, http://www.darwinsys.com/
version
$Id: FileProperties.java,v 1.10 2004/03/07 17:14:56 ian Exp $

Fields Summary
protected String
fileName
The name of the file this FileProperties represents.
private boolean
exists
True 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 voidclose()
No longer needed.

deprecated
No longer needed.

		// Nothing to do
	
public java.lang.StringgetFileName()

		return fileName;
	
public java.util.Propertiesload()
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 voidsave()
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();
	
voidsetFileName(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;
			}
		}