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:
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 line number of it which mean 1,2,3 is in line 1 and 3,4,5 is in line 2.How do I get that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…