A: 

You need to assign the file, open it, and reset to the beginning. You don't show any of that.

Chris Thornton
http://java.sun.com/javase/6/docs/api/java/util/Scanner.htmlIt's possible that he has already done that outside this method.
Vivin Paliath
+5  A: 

I don't know why it does not work (and the code below will not fix it), but

  for(int i=0; i < line.length(); i++)
            count++;

can be written more concise as

  count += line.length();
Thilo
+3  A: 

Why are you using a Scanner ? A simple Reader would suffice. If you insist in using a Scanner, you must understand that it divides its input in fields separated by some pattern (a space by default), perhaps one can set an empty pattern so that the fields correspond with the characters (but again, that would be overkill, just use a Reader)

leonbloy
A: 

What delimiter are you setting for the scanner? You don't show it in your code, but you need to make it treat a line as a single token.

scanner.useDelimiter("\n");

Also, you say that the second code example worked perfectly. Did you print out the value of line to verify that it contained anything? It might have counted the lines properly, but if line didn't actually contain anything then that would help explain why it doesn't enter your for loop.

Binary Nerd
The test file I use has a blank line in it to test to see if it is counted and the code I have does count it.
Kat
And you used a different file as the input to your counting characters example i assume?
Binary Nerd
+1  A: 

Have you already read everything from the Scanner before passing it to getcharCount()?

Stephen Denne
A: 

I haven't worked with Scanner too much, but wouldn't

textFile.hasNextline();

make a little more sense than

textFile.hasNext();

Just a thought--I'm not sure if that would have any major effect on the execution

mportiz08