home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / javafile / ch10 / BufferedReadDataStream.java < prev    next >
Encoding:
Java Source  |  1998-12-14  |  1.1 KB  |  39 lines

  1.  
  2. import java.io.*;
  3.  
  4. public class BufferedReadDataStream
  5. {
  6.     // This program runs as an application
  7.     public static void main(String[] arguments)
  8.     {
  9.         try
  10.         {
  11.             //declare a stream
  12.             FileInputStream ifile = new FileInputStream("bufDouble.dat");
  13. BufferedInputStream bufStream = new BufferedInputStream(ifile);
  14. DataInputStream datStream = new DataInputStream(bufStream);
  15. int cntDoubles = 0;
  16.             try
  17.             {
  18.                 while (true)
  19.                 {
  20.                     double thisVal = datStream.readDouble();
  21.                     System.out.print( thisVal + " ");
  22.                     cntDoubles++;
  23.                 } //while
  24.             } catch (EOFException eof)
  25.                 {
  26.                     datStream.close();
  27.                     System.out.print("\nDoubles read: " + [ccc]
  28. cntDoubles);
  29. } //catch
  30.  
  31.        } catch (IOException e)// handle any errors
  32.             {
  33.                 System.out.println("Error - " + e.toString());
  34.             }//catch
  35.     }//main
  36. }//BufferedReadDataStream
  37.  
  38.  
  39.