How to store objects in file?
This example demonstrate how to use the
ObjectInputStream to write and read serialized object. To do this below we create a
Book that implements
java.io.Serializable interface. The book class have a constructor that accept all the book detail information.
To write an object to a stream call the
writeObject() method of the
ObjectOutputStream class and pass the serialized object to it. To read the object call the
readObject() method of the