Deserializing object

JAVA PRIMER
Using Java Object Serialization: A Few Pitfalls
Huw Evans
Listing 2. Deserializing object "o" from the file "store."


1   import java.io.*;
2   public class Deserialize
3   {
4     public static void main(String argv[])
5     {
6       ObjectInputStream in = null;
7       FileInputStream file = null;
8       O o = null;
9       try {
10         file = new FileInputStream("store");
11         in = new ObjectInputStream(file);
12         o = (O) in.readObject();
13         in.close();
14       } catch(java.io.IOException ioe) {
15         ioe.printStackTrace();
16         System.exit(1);
17       } catch(java.lang.ClassNotFoundException cnfe) {
18         cnfe.printStackTrace();
19         System.exit(2);
20       }
21       System.out.println(o);
22     }
23   }

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.