// Function to copy all lines from a specified line number onward
public static List copyLinesFrom(String filePath, int startLine) throws IOException {
List lines = new ArrayList<>();
int currentLine = 0;
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = reader.readLine()) != null) {
currentLine++;
if (currentLine >= startLine) {
lines.add(line);
}
}
}
return lines;
}
New contributor
Upkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1