Java IO Tutorial - Java CharArrayReader.reset()








Syntax

CharArrayReader.reset() has the following syntax.

public void reset()  throws IOException

Example

In the following code shows how to use CharArrayReader.reset() method.

/*from www.ja  va2s.  c o m*/
import java.io.CharArrayReader;

public class Main {
  public static void main(String[] args) throws Exception {
    char[] ch = { 'A', 'B', 'C', 'D', 'E' };

    CharArrayReader car = new CharArrayReader(ch);

    int value = 0;

    while ((value = car.read()) != -1) {
      System.out.print((char) value);
    }
    car.reset();
    while ((value = car.read()) != -1) {
      System.out.print((char) value);
    }

  }
}

The code above generates the following result.