I want to read a text file in java. I know how to read line by line from a text file by java. My question is if I have a text file that has 500 lines. I want to read the file from the 50th line to the 150th line by counting the line number first of the file. Can it be possible using LineNumberReader or any other class? I don't want to use line.equals("something")
method.
I am a beginner.
So far, I tried:
public class ReadLine{
public static void main(String[] args) {
File file = new File("H://java//newFile.txt");
try {
LineNumberReader linenumber = new LineNumberReader(new FileReader(file));
linenumber.setLineNumber(50);
String line = null;
for (int i = linenumber.getLineNumber(); i < 151; i++) {
System.out.println("line=" + linenumber.readLine());
}
} catch (Exception e) {
}
}
}