01: import java.io.*;
02:
03: /**
04: A program that serializes and deserializes an Employee array.
05: */
06: public class SerializeEmployeeTest
07: {
08: public static void main(String[] args)
09: 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 (int i = 0; i < staff2.length; i++)
25: System.out.println(staff2[i]);
26: }
27: }