I\'m using scanner to read a text file line by line but then how to get line number since scanner iterates through each input?My program is something like this:
Just put a counter in the loop:
s = new Scanner(new BufferedReader(new FileReader("input.txt"))); for (int lineNum=1; s.hasNext(); lineNum++) { System.out.print("Line number " + lineNum + ": " + s.next()); }