Java ObjectOutputStream.close()
Syntax
ObjectOutputStream.close() has the following syntax.
public void close() throws IOException
Example
In the following code shows how to use ObjectOutputStream.close() method.
// w w w . jav a 2s.c om
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Main {
public static void main(String[] args) {
Card card = new Card();
try {
FileOutputStream out = new FileOutputStream("card.out");
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(card);
oos.flush();
oos.close();
} catch (Exception e) {
System.out.println("Problem serializing: " + e);
}
}
}
class Card implements Serializable {
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »