Byte Reader with FileInputStream : Byte Read Write « File Input Output « Java






Byte Reader with FileInputStream

     

import java.io.FileInputStream;
import java.io.IOException;

public class ByteReader {
  public static void main(String[] arguments) {
    try {
      FileInputStream file = new FileInputStream("class.dat");
      boolean eof = false;
      int count = 0;
      while (!eof) {
        int input = file.read();
        System.out.print(input + " ");
        if (input == -1)
          eof = true;
        else
          count++;
      }
      file.close();
      System.out.println("\nBytes read: " + count);
    } catch (IOException e) {
      System.out.println("Error - " + e.toString());
    }
  }
}

            

   
    
    
    
  








Related examples in the same category

1.Byte Writer with FileOutputStream
2.Binary Dump OutputStream
3.Compare binary files
4.Reads bytes available from one InputStream and returns these bytes in a byte array.
5.Buffered copying between source(InputStream, Reader, String and byte[]) and destinations (OutputStream, Writer, String and byte[]).
6.Write and read compressed forms of numbers to DataOutput and DataInput interfaces.
7.Count the number of bytes written to the output stream.
8.Read and return the entire contents of the supplied file.
9.Convert 4 hex digits to an int, and return the number of converted bytes.
10.Get bytes from InputStream
11.Read file as bytesRead file as bytes