Lecture Videos
  1  import java.io.*;
  2  
  3  public class DetectEndOfFile { 
  4    public static void main(String[] args) {
  5      try {
  6        try (DataOutputStream output = 
  7          new DataOutputStream(new FileOutputStream("test.dat"))) {
  8          output.writeDouble(4.5);
  9          output.writeDouble(43.25);
 10          output.writeDouble(3.2);
 11        }
 12        
 13        try (DataInputStream input = 
 14          new DataInputStream(new FileInputStream("test.dat"))) {
 15          while (true) 
 16            System.out.println(input.readDouble());
 17        }
 18      }
 19      catch (EOFException ex) {
 20        System.out.println("All data were read");
 21      }
 22      catch (IOException ex) {
 23        ex.printStackTrace();
 24      }
 25    }
 26  }