reading nth line onwards
java
5 years, 1 month ago
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.Scanner;
public class ReadLine {
public static void main(String[] args) {
StringBuffer buffer = new StringBuffer();
String line = "";
int lineNo;
Scanner input = new Scanner(System.in);
System.out.print("Enter Line Number: ");
int no = input.nextInt();
try {
LineNumberReader ln =
new LineNumberReader(new FileReader("/Users/abc.txt"));
int count = 0;
while (ln.readLine() != null) {
count++;
}
ln.close();
FileReader fr = new FileReader("/Users/abc.txt");
BufferedReader br = new BufferedReader(fr);
for (lineNo = 1; lineNo <= count; lineNo++) {
if (lineNo == no) {
for (lineNo = no; lineNo <= count; lineNo++) {
buffer.append(br.readLine());
buffer.append("\n");
}
} else br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(buffer.toString());
}
}
1 Comments
Please Login to Comment Here