LineNumberReader skip Example
LineNumberReader class skip example. This example shows you how to use skip method.
LineNumberReader class skip example.public long skip(long n) throws IOException Skip characters.
Here is the code
/**
* @ # Skip.java
* A class repersenting use to skip method
* of LineNumberReader class in java.io package
* version 28 May 2008
* author Rose India
*/
import java.io.*;
public class Skip {
public static void main(String args[]) throws Exception {
// Create a new instance of a LineNumberReader object
// that is reading from a FileReader object.
File myFile = new File("text.txt");
FileReader fileReader = new FileReader(myFile);
LineNumberReader reader = new LineNumberReader(fileReader);
// Read from the FileReader.
int charRead;
int skipCount = 0;
while ((charRead = reader.read()) >= 0) {
System.out.print((char) charRead);
// Skip over some characters.
reader.skip(++skipCount);
}
// Determine the number of lines that were read.
System.out.println("\nTotal lines read: " +
reader.getLineNumber());
// Close the LineNumberReader and FileReader.
fileReader.close();
reader.close();
}
} |
Output
Tiiyecslil
Total lines read: 3 |
|