Java IO Tutorial - Java BufferedInputStream.read()








Syntax

BufferedInputStream.read() has the following syntax.

public int read()  throws IOException

Example

In the following code shows how to use BufferedInputStream.read() method.

// w  ww  .  j av a2  s  .  c o  m



import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;

public class Main {
  public static void main(String[] args) throws Exception {

    InputStream inStream = new FileInputStream("c:/test.txt");

    BufferedInputStream bis = new BufferedInputStream(inStream);

    // read until a single byte is available
    while (bis.available() > 0) {
      // read the byte and convert the integer to character
      char c = (char) bis.read();

      System.out.println(c);
    }
  }
}