Java IO Tutorial - Java BufferedInputStream

A BufferedInputStream adds functionality to an input stream by buffering the data.

It maintains an internal buffer to store bytes read from the underlying input stream.

We create the buffer input stream as follows:

String srcFile = "test.txt"; BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile));

The following code shows how to read from a File Using a BufferedInputStream.

/*ww  w  .  j  av a 2  s  .c  om*/
public class Main {
  public static void main(String[] args) {
    String srcFile = "test.txt";
    try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
        srcFile))) {
      // Read one byte at a time and display it
      byte byteData;
      while ((byteData = (byte) != -1) {
        System.out.print((char) byteData);
    } catch (Exception e2) {

The code above generates the following result.