Java IO Tutorial - Java[] cbuf, int off, int len)

Syntax[] cbuf, int off, int len) has the following syntax.

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


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

//w  w w. ja v a  2s .c om

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

    char[] cbuf = new char[6];
    int i = 0;

    Reader r = new StringReader("ABCDEF");

    FilterReader fr = new FilterReader(r) {

    // read data of len 4, to the buffer
    i =, 2, 4);
    System.out.println("No. of characters read: " + i);

    // read till the end of the char buffer
    for (char c : cbuf) {
      // checks for the empty character in buffer
      if ((byte) c == 0)
        c = '-';



The code above generates the following result.