Guest User

Untitled

a guest
Mar 12th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. //Read File
  2. import java.io.FileInputStream;
  3. import java.io.ObjectInputStream;
  4. import java.io.IOException;
  5. import java.io.EOFException;
  6.  
  7. public class ReadFile
  8. {
  9.     private FileInputStream fis;
  10.     private ObjectInputStream ois;
  11.     private Record r;
  12.  
  13.     public ReadFile()
  14.     {
  15.         try
  16.         {
  17.             fis = new FileInputStream("Clients.ser");
  18.             ois = new ObjectInputStream(fis);
  19.         }
  20.         catch(IOException ioe) { System.out.println("error"); }
  21.         try
  22.         {
  23.             while(true)
  24.             {
  25.                 //cast according to class Record
  26.                 r = (Record) ois.readObject();
  27.                 System.out.print(r.account + r.firstName + r.lastName + r.balance);
  28.             }
  29.         }
  30.         catch(IOException ioe) { System.out.println("ioexception"); }
  31.         catch(ClassNotFoundException cnfe) {System.out.println("classnotfound"); }
  32.     }
  33.  
  34.     public static void main(String args[])
  35.     {
  36.         ReadFile rf = new ReadFile();
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment