Java FileOutputStream finalize() Example
FileOutputStream class finalize() method example. This example shows you how to use finalize() method.
Syntax is : protected void finalize() throws IOException
This method cleans up the connection to the file, and ensures that the close method of this file output stream is called when there are no more references to this stream.
Here is the code.
/**
* @(#) FinalizeFileOutputStream.java
* A class representing use of method finalize() of FileOutputStream
class in java.io Package.
* @Version 05-June-2008
* @author Rose India Team
*/
import java.io.*;
public class FinalizeFileOutputStream extends FileOutputStream {
// Contructor definition of the FinalizeFileOutputStream class.
public FinalizeFileOutputStream() throws IOException{
super("Mahendra Singh"); // call the super class constructor.
}
public static void main(String[] args) throws IOException {
// Create object of FinalizeFileOutputStream class.
FinalizeFileOutputStream objOutstream = new FinalizeFileOutputStream();
// finalize() method call.
objOutstream.finalize();
System.out.print("Stream is closed successfully and connection has "+
"cleaned up to the file.");
}
} |
output of the program.
| Stream is closed successfully and connection has cleaned up to the file. |
|