El método close() de la clase ObjectInputStream en Java cierra el flujo de entrada.
Sintaxis :
public void close()
Parámetros: Este método no acepta ningún parámetro.
Valor devuelto: este método no devuelve nada.
El siguiente programa ilustra el método anterior:
Programa 1:
// Java program to illustrate // the above method import java.io.*; public class GFG { public static void main(String[] args) throws Exception { try { // Creates a new file // with an ObjectOutputStream FileOutputStream out = new FileOutputStream("gopal.txt"); ObjectOutputStream out1 = new ObjectOutputStream(out); // write in the file out1.writeUTF("Geeks for Geeks"); // FLushes the stream out1.flush(); // Create an ObjectInputStream // for the file we created before ObjectInputStream example = new ObjectInputStream( new FileInputStream("gopal.txt")); // read from the stream for (int i = 0; i < example.available();) { System.out.println("" + (char)example.read()); } // closes the stream System.out.println("\nClosing Stream..."); example.close(); // Stream closed System.out.println("Stream Closed."); } catch (Exception ex) { ex.printStackTrace(); } } }
Referencia : https://docs.oracle.com/javase/10/docs/api/java/io/ObjectInputStream.html#close()