- Serialization is the process of transforming an in-memory object to a byte stream.
- An object is serialized by writing it to an ObjectOutputStream.
- Serialization Code
ObjectOutputStream oos = new ObjectOutputStream( out );
oos.writeObject(new String ());
oos.close ();
- Deserialization is the inverse process of reconstructing an object from a byte stream to the same state in which the object was previously serialized.
- An object is deserialized by reading it from an ObjectInputStream.
- Deserialization Code
FileInputStream in = new FileInputStream( "test.txt" );
ObjectInputStream ois = new ObjectInputStream( in );
String s = (String) ois.readObject();
ois.close();
No comments:
Post a Comment