Java CharArrayReader create from char array

Description

Java CharArrayReader create from char array

import java.io.CharArrayReader;
import java.io.IOException;

public class Main {

  public static void main(String args[]) throws IOException {
    char c[] = {'a','v','c','d','e',};
    CharArrayReader input1 = new CharArrayReader(c);
    //from  w  ww . j a  v a  2s  . com
    int i;
    System.out.print("input1 is:");
    while ((i = input1.read()) != -1) {
      System.out.print((char) i);
    }

  }
}

import java.io.CharArrayReader;
import java.io.IOException;

public class Main {
  public static void main(String args[]) throws IOException {
    String tmp = "test from demo2s.com";
    int length = tmp.length();
    char c[] = new char[length];

    tmp.getChars(0, length, c, 0);/*from w w  w . j a  va  2  s.  c om*/
    CharArrayReader input1 = new CharArrayReader(c);
    CharArrayReader input2 = new CharArrayReader(c, 0, 5);

    int i;
    while ((i = input1.read()) != -1) {
      System.out.print((char) i);
    }

    while ((i = input2.read()) != -1) {
      System.out.print((char) i);
    }
  }
}



PreviousNext

Related