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

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