Java IO Tutorial - Java FileInputStream.finalize()








Syntax

FileInputStream.finalize() has the following syntax.

protected void finalize()   throws IOException

Example

In the following code shows how to use FileInputStream.finalize() method.

/*w  w  w  .  j  a v a2 s. co m*/

import java.io.FileInputStream;

public class Main extends FileInputStream {
  public Main() throws Exception {
    super("C://test.txt");
  }

  public static void main(String[] args) throws Exception {
    Main fisa = new Main();

    // read byte from file input stream
    int i = fisa.read();

    // converts int to char
    char c = (char) i;
    System.out.println(c);

    // finalize method invoked
    fisa.finalize();

    // method revoked after finalize metod
    i = fisa.read();
    c = (char) i;
    System.out.println(c);

  }
}