Java FilterReader.skip(long n)
Syntax
FilterReader.skip(long n) has the following syntax.
public long skip(long n) throws IOException
Example
In the following code shows how to use FilterReader.skip(long n) method.
//w w w . j av a2s .com
import java.io.FilterReader;
import java.io.Reader;
import java.io.StringReader;
public class Main {
public static void main(String[] args) throws Exception {
int i = 0;
// create new reader
Reader r = new StringReader("from java2s.com");
// create new filter reader
FilterReader fr = new FilterReader(r) {
};
// read till the end of the filter reader
while ((i = fr.read()) != -1) {
// convert integer to character
char c = (char) i;
// prints
System.out.println("Character read: " + c);
// number of characters actually skipped
long l = fr.skip(2);
// prints
System.out.println("Character skipped: " + l);
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »