Java BufferedReader skip() Method
Example
Skip the first 6 characters, then read the rest of the line:
import java.io.BufferedReader;
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();
BufferedReader br = new BufferedReader(new FileReader("filename.txt"));
br.skip(6);
System.out.println(br.readLine());
br.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
❮ BufferedReader Methods