Java IO Tutorial - Java ObjectOutputStream (OutputStream out) Constructor








Syntax

ObjectOutputStream(OutputStream out) constructor from ObjectOutputStream has the following syntax.

public ObjectOutputStream(OutputStream out)     throws IOException

Example

In the following code shows how to use ObjectOutputStream.ObjectOutputStream(OutputStream out) constructor.

//www. ja v a  2  s  .  co  m
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 {

}