Java IO Tutorial - Java CharArrayReader.skip(long n)








Syntax

CharArrayReader.skip(long n) has the following syntax.

public long skip(long n)  throws IOException

Example

In the following code shows how to use CharArrayReader.skip(long n) method.

/*ww w  .ja v  a  2 s.  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;

    // read till the end of the stream
    while ((value = car.read()) != -1) {
      // convert integer to char
      char c = (char) value;

      // print characters
      System.out.print(c + "; ");

      // skip single character
      long l = car.skip(1);
      System.out.println("Characters Skipped : " + l);
    }
  }
}

The code above generates the following result.