Help!! Counting Lines in a text file.

I need to count the number of lines in a text file, the only thing is that we can't use the BufferReader class. Instead we have to use the Scanner class. Any help would be greatly appreciated! I tried this but it didnt work.

Scanner inFile = new Scanner(new FileReader("Document.txt")

int numLines = 0;

while(inFile.hasNextLine())

{

numLines++;

}

[390 byte] By [thaxphenomxa] at [2007-11-26 16:09:33]
# 1
Out of curiosity, why can't you use BufferedReader? And what about [url= http://java.sun.com/j2se/1.5.0/docs/api/java/io/LineNumberReader.html]LineNumberReader?[/url]
DrLaszloJamfa at 2007-7-8 22:31:52 > top of Java-index,Java Essentials,Java Programming...
# 2
I'm guessing you end up in an infinite loop since hasNextLine() will never be false. Try actually reading a line inside the loop.
floundera at 2007-7-8 22:31:52 > top of Java-index,Java Essentials,Java Programming...