Serializing object
- By Huw Evans
- September 12, 2000
JAVA PRIMERUsing Java Object Serialization: A Few Pitfalls
Huw Evans
Listing 1. Serializing object "o" to the file "store."
1 import java.io.*;
2 public class Serialize
3 {
4 public static void main(String argv[])
5 {
6 ObjectOutputStream out = null;
7 FileOutputStream file = null;
8 try {
9 file = new FileOutputStream("store");
10 out = new ObjectOutputStream(file);
11 O o = new O();
12 out.writeObject(o);
13 out.close();
14 } catch(java.io.IOException ioe) {
15 ioe.printStackTrace();
16 System.exit(1);
17 }
18 }
19 }