//******************************************************************** // CS 201 WriteObjects.java // // Object Serialization. //******************************************************************** import java.util.*; import java.io.*; public class WriteObjects { //----------------------------------------------------------------- // Creates several object and writes them to a file. //----------------------------------------------------------------- public static void main (String[] args) throws Exception { Scanner scan = new Scanner(System.in); String fileName, name, address, dateOfBirth; System.out.print("\n\nEnter the output file name: "); fileName = scan.nextLine(); FileOutputStream outFile = new FileOutputStream (fileName); ObjectOutputStream outStream = new ObjectOutputStream (outFile); Person[] persons = new Person[4]; for(int i = 0; i < persons.length; i++) { System.out.print("\n\nEnter the name: "); name = scan.nextLine(); System.out.print("\nEnter the address: "); address = scan.nextLine(); System.out.print("\nEnter the date of birth: "); dateOfBirth = scan.nextLine(); persons[i] = new Person(name,address,dateOfBirth); } for(int i = 0; i < persons.length; i++) outStream.writeObject (persons[i]); outStream.close(); } }