/home/wpollock1/public_html/AJava/Finalizer.java
// Demo of Finalizers. Not a complete program!
// Written 2/2001 by Wayne Pollock, Tampa Florida USA
public class DBFile
{
private FileReader file;
public DBFile ( String fileName ) throws FileNotFoundException
{
file = new FileReader( fileName );
}
public synchronized void close () throws IOException
{
if ( file != null )
{ file.close();
file = null;
}
}
protected void finalize () throws Throwable
{ try
{ close();
}
finally
{ super.finalize(); // Always use this.
}
}
}