How to read object from a file in java

In this post, we will see how to read object from file in java. In last post, we have already seen how to write object to a file and created employee.ser , now in this post, we are going to read same file and retrieve back Employee object.

Java Serialization Tutorial:

Reading object from file using ObjectInputStream may be referred as Deserialization.

Lets take an example:
Create Employee.java same as last example in src->org.arpit.java2blog

1.Employee.java

Create DeserializeMain.java in src->org.arpit.java2blog
2.DeserializeMain.java

3.Run it:

When you run above DeserializeMain.java and you will get following output:
These are some simple steps to read object from file. If you want to go through some complex scenario you can go through Serialization in java

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *