Java IO Tutorial - Java CharArrayReader.read(char[] b, int off, int len)








Syntax

CharArrayReader.read(char[] b, int off, int len) has the following syntax.

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

Example

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

//from  w w  w.  jav a2  s . co m
import java.io.CharArrayReader;

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

    char[] ch = { 'H', 'E', 'L', 'L', 'O' };

    char[] d = new char[5];


    CharArrayReader car = new CharArrayReader(ch);

    // read character to the destination buffer
    car.read(d, 3, 2);

    // for every character in the buffer
    for (char c : d) {
      int i = (int) c;
      if (i == 0) {
        System.out.println("0");
      } else {
        System.out.println(c);
      }
    }

  }
}

The code above generates the following result.