@@ -0,0 +1,1726 @@
+package chapter15;%0A%0Aimport java.io.EOFException;%0Aimport java.io.IOException;%0Aimport java.io.ObjectInputStream;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Paths;%0A%0Apublic class ReadSequentialFile %7B%0A%0A%09private static ObjectInputStream input;%0A%09%0A%09public static void main(String%5B%5D args) %7B%0A%09%09openFile();%0A%09%09readRecords();%0A%09%09closeFile();%0A%09%7D%0A%09%0A%09// enable user to select file to open%0A%09public static void openFile() %7B%0A%09%09try %7B // open file%0A%09%09%09input = new ObjectInputStream(Files.newInputStream(Paths.get(%22clients.ser%22)));%0A%09%09%7D catch (IOException ioException) %7B%0A%09%09%09System.err.println(%22Error opening file.%22);%0A%09%09%09System.exit(1);%0A%09%09%7D%0A%09%7D%0A%09%0A%09// read record from file%0A%09public static void readRecords() %7B%0A%09%09System.out.printf(%22%25-10s%25-12s%25-12s%2510s%25n%22, %22Account%22, %22First Name%22, %22Last Name%22, %22Balance%22);%0A%09%09%0A%09%09try %7B%0A%09%09%09while (true) %7B // loop until there is an EOFException%0A%09%09%09%09Account record = (Account) input.readObject();%0A%09%09%09%09%0A%09%09%09%09// display record contents%0A%09%09%09%09System.out.printf(%22%25-10d%25-12s%25-12s%2510.2f%25n%22, record.getAccount(), record.getFirstName(),%0A%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09record.getLastName(), record.getBalance());%0A%09%09%09%7D%0A%09%09%7D catch (EOFException endOfFileException) %7B%0A%09%09%09System.out.printf(%22%25nNo more records%25n%22);%0A%09%09%7D catch (ClassNotFoundException classNotFoundException) %7B%0A%09%09%09System.err.println(%22Invalid object type. Terminating.%22);%0A%09%09%7D catch (IOException ioException) %7B%0A%09%09%09System.err.println(%22Error reading from file. Terminating%22);%0A%09%09%7D%0A%09%7D // end method readRecords%0A%09%0A%09// close file and terminate application%0A%09public static void closeFile() %7B%0A%09%09try %7B%0A%09%09%09if (input != null)%0A%09%09%09%09input.close();%0A%09%09%7D catch (IOException ioException) %7B%0A%09%09%09System.err.println(%22Error closing file. Terminating.%22);%0A%09%09%09System.exit(1);%0A%09%09%7D%0A%09%7D%0A%09%0A%7D // end class ReadSequentialFile%0A

Create ReadSequentialFile.java