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.


/* ww w .j a v  a 2s.co 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);
    }
  }
}