I use a scanner to read a text file line by line, but then how to get the line number, since the scanner iterates through each input? My program looks something like this:
s = new Scanner(new BufferedReader(new FileReader("input.txt"))); while (s.hasNext()) { System.out.print(s.next());
This works fine, but for example:
1,2,3
3,4,5
I want to know the line number, which means that 1,2,3 is on line 1, and 3,4,5 is on line 2. How do I get this?
java java.util.scanner
gingergeek
source share