Java BufferedInputStream read byte from file

Description

Java BufferedInputStream read byte from file

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

public class Main {
  public static void main(String[] args) {
    String srcFile = "Main.java";

    try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
        srcFile))) {/*from  ww w  . j  a va 2 s  . co  m*/
      // Read one byte at a time and display it
      byte byteData;
      while ((byteData = (byte) bis.read()) != -1) {
        System.out.print((char) byteData);
      }
    } catch (IOException e2) {
      e2.printStackTrace();
    }
  }
}



PreviousNext

Related