001package horstmann.ch07_serial1;
002import java.io.FileInputStream;
003import java.io.FileOutputStream;
004import java.io.IOException;
005import java.io.ObjectInputStream;
006import java.io.ObjectOutputStream;
007
008/**
009   A program that serializes and deserializes an Employee array.
010 */
011public class SerializeEmployeeTester
012{
013        public static void main(String[] args)
014                        throws IOException, ClassNotFoundException
015        {
016                Employee[] staff = new Employee[2];
017                staff[0] = new Employee("Fred Flintstone", 50000);
018                staff[1] = new Employee("Barney Rubble", 60000);
019                staff[0].setBuddy(staff[1]);
020                staff[1].setBuddy(staff[0]);
021                ObjectOutputStream out = new ObjectOutputStream(
022                                new FileOutputStream("staff.dat"));
023                out.writeObject(staff);
024                out.close();
025                ObjectInputStream in = new ObjectInputStream(
026                                new FileInputStream("staff.dat"));
027                Employee[] staff2 = (Employee[]) in.readObject();
028                in.close();
029                for (Employee e : staff2)
030                        System.out.println(e);
031        }
032}