Java IO Tutorial - Java BufferedReader.read(char[] cbuf, int off, int len)








Syntax

BufferedReader.read(char[] cbuf, int off, int len) has the following syntax.

public int read(char[] cbuf, int off, int len)  throws IOException

Example

In the following code shows how to use BufferedReader.read(char[] cbuf, int off, int len) method.

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
// w w  w  .  j  a v a 2 s  .  c  om
public class Main {
  public static void main(String[] args) throws Exception {
    InputStream is = new FileInputStream("c:/test.txt");

    InputStreamReader isr = new InputStreamReader(is);

    BufferedReader br = new BufferedReader(isr);

    char[] cbuf = new char[is.available()];

    br.read(cbuf, 2, 10);

    for (char c : cbuf) {
      if (c == (char) 0) {
        c = '*';
      }
      // prints characters
      System.out.print(c);
    }
  }
}