How do I store objects in file?


This example demonstrate how to use the ObjectOutputStream and 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 ObjectInputStream.

Filed in: Java IO
© 2014 Java Examples - Built with love by Wayan Saryada.