Java I/O How to - Read File via Buffered Stream








Question

We would like to know how to read File via Buffered Stream.

Answer

 /* w ww .j ava 2s.  com*/


import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

public class Main {

  public static void main(String[] args) throws Exception {
    File file = new File("C:/ReadFile.txt");
    FileInputStream fin = new FileInputStream(file);

    BufferedInputStream bin = new BufferedInputStream(fin);
    while (bin.available() > 0) {
      System.out.println((char) bin.read());
    }
    bin.close();
  }
}