Java BufferedInputStream read int/char from file

Description

Java BufferedInputStream read int/char 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 w  w w .ja va2 s. c o m*/
      // Read one int at a time and display it
      int data;
      while ((data = bis.read()) != -1) {
        System.out.print((char) data);
      }
    } catch (IOException e2) {
      e2.printStackTrace();
    }
  }
}



PreviousNext

Related