Object Streams and Serialization : Serialization « File « SCJP






import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class MainClass {
  public static void main(String[] argv)throws Exception {

    StringBuilder writeMe = new StringBuilder();
    FileOutputStream fos = new FileOutputStream("sbuf.ser");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(writeMe);
    oos.close();
    fos.close();

    FileInputStream fis = new FileInputStream("sbuf.ser");
    ObjectInputStream ois = new ObjectInputStream(fis);
    StringBuffer sb = (StringBuffer) ois.readObject();
    ois.close();
    fis.close();

  }
}








9.5.Serialization
9.5.1.Object Serialization
9.5.2.Object Streams and Serialization
9.5.3.Wirte your own serialization code
9.5.4.Working with ObjectOutputStream and ObjectInputStream
9.5.5.Serialize a hierarchy
9.5.6.Using writeObject and readObject
9.5.7.Which variables will and will not be restored with the appropriate values when an object is deserialized