Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. class Test
  2. {
  3.     public static void main(String[] args)
  4.     {    
  5.         Object object1 = null;
  6.        try
  7.         {    
  8.             // Reading the object from a file
  9.             FileInputStream file = new FileInputStream(filename);
  10.             ObjectInputStream in = new ObjectInputStream(file);
  11.              
  12.             // Method for deserialization of object
  13.             // We have to cast the object read from the byte stream to a Dog
  14.             object1 = (Dog)in.readObject();
  15.              
  16.             in.close();
  17.             file.close();
  18.              
  19.             System.out.println("Object has been deserialized ");
  20.             System.out.println("a = " + object1.a);
  21.             System.out.println("b = " + object1.b);
  22.         }
  23.          
  24.         catch(IOException ex)
  25.         {
  26.             System.out.println("IOException is caught");
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement