Why does my loop run to infinity instead of stopping at some point even though when there is finite(10) number of lines in my text file.
import java.util.*;
import java.io.*;
public class numberOfLines{
public static void main(String[] args){
try{
Scanner cs=new Scanner(new File("poem.txt"));
int i=0;
while(cs.hasNextLine()){
System.out.println(i);
}
} catch(FileNotFoundException e){
System.out.print("File not found");
}
}
}
Thanks in advance for your help on this problem.