read first 5 lines of text file java scanner code example
Example: how to check the lines in a file java scanner
int count = 0;
while (scanner.hasNextLine()) {
count++;
scanner.nextLine();
}
int count = 0;
while (scanner.hasNextLine()) {
count++;
scanner.nextLine();
}