How to read object from a file in java

Previous
Next
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

Previous
Next

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.

Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog