Java Reader.skip(long n)
Syntax
Reader.skip(long n) has the following syntax.
public long skip(long n) throws IOException
Example
In the following code shows how to use Reader.skip(long n) method.
import java.io.*;
//from ww w . j a v a 2s . co m
public class Main {
public static void main(String[] args) {
String s = "tutorial from java2s.com";
Reader reader = new StringReader(s);
try {
// read the first five chars
for (int i = 0; i < 5; i++) {
char c = (char) reader.read();
// skip a char every time
reader.skip(1);
System.out.println(c);
}
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »