DeSerialization in java with Example

DeSerialization in java with Example

DeSerialization is the process converting the serialized form of an object back into a copy of the object.

We can implement Deserialization by using FileInputStreamand ObjectInputStream

Example


package com.java2study;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

public class DeserialzationDemo {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
FileInputStream fis = new FileInputStream("student.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
Student s2 = (Student)ois.readObject();
System.out.println(s2.getStudentId()+" "+s2.getStudentName()+" " +s2.getFee());


}

}

output


1 ABC 1400.0

-->