Java FileReader skip() Method
Example
Skip the first 6 characters of a file, then read the next character:
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
FileWriter myWriter = new FileWriter("filename.txt");
myWriter.write("Hello World");
myWriter.close();
FileReader myReader = new FileReader("filename.txt");
System.out.println(myReader.skip(6));
System.out.println((char) myReader.read());
myReader.close();
}
}
Definition and Usage
The skip() method skips (jumps over) a number of characters, so they are not read.
It returns the number of characters that were really skipped. This can be less than you asked for, if the end of the file comes first.
Syntax
public long skip(long n)
Parameter Values
| Parameter | Description |
|---|---|
| n | Required. The number of characters to skip. |
Technical Details
| Returns: | The number of characters that were skipped, as a long. |
|---|---|
| Throws: | IllegalArgumentException - if n is negative. |
Related Pages
❮ FileReader Methods