Source of Question29.java


  1: import java.io.ObjectInputStream;
  2: import java.io.EOFException;
  3: import java.io.FileInputStream;
  4: import java.io.IOException;
  5: 
  6: public class Question29
  7: {
  8:    public static final String FILE_NAME = "temperatures.dat";
  9:    public static void main(String[] args)
 10:    {
 11:       try
 12:       {
 13:          ObjectInputStream inputStream = 
 14:                         new ObjectInputStream(
 15:                                new FileInputStream(FILE_NAME));
 16:          System.out.println("Numbers from the file " + 
 17:                              FILE_NAME + ":");
 18:          try
 19:          {
 20:             while (true)
 21:             {
 22:                double number = inputStream.readDouble( );
 23:                System.out.println(number); 
 24:             }
 25:          }
 26:          catch(EOFException e)
 27:          {
 28:             //Do nothing
 29:          }
 30:          System.out.println("End of reading from file.");
 31:          inputStream.close( );
 32:       }
 33:       catch(IOException e)
 34:       {
 35:           System.out.println("Problem reading from file.");
 36:       }
 37:    }
 38: }