public class SerializeEmployeeTester
1: import java.io.*;
3: /**
4: A program that serializes and deserializes an Employee array.
5: */
6: public class SerializeEmployeeTester
7: {
8: public static void main(String[] args)
9: throws IOException, ClassNotFoundException
10: {
11: Employee[] staff = new Employee[2];
12: staff[0] = new Employee("Fred Flintstone", 50000);
13: staff[1] = new Employee("Barney Rubble", 60000);
14: staff[0].setBuddy(staff[1]);
15: staff[1].setBuddy(staff[0]);
16: ObjectOutputStream out = new ObjectOutputStream(
17: new FileOutputStream("staff.dat"));
18: out.writeObject(staff);
19: out.close();
20: ObjectInputStream in = new ObjectInputStream(
21: new FileInputStream("staff.dat"));
22: Employee[] staff2 = (Employee[]) in.readObject();
23: in.close();
24: for (Employee e : staff2)
25: System.out.println(e);
26: }
27: }