Answer : To deserialize an object, perform the following steps:
- Open an input stream -
- Chain it with the ObjectInputStream
- Call the method readObject() and cast the returned object to the class that is being deserialized.
- Close the streams
Java Code
try{
fIn= new FileInputStream("c:\\emp.ser");
in = new ObjectInputStream(fIn);
//de-serializing employee
Employee emp = (Employee) in.readObject();
System.out.println("Deserialized " + emp.fName + " " + emp.lName + " from emp.ser ");
}catch(IOException e){
e.printStackTrace();
}catch(ClassNotFoundException e){
e.printStackTrace(); }
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment