im new to java and encountered this problem on homework. Im doing my best but cant find the error anywhere.
here is the code.
import java.io.*;
public class SEPrep7g
{
public static void main(String[] args) throws IOException
{
System.out.println("Program Results for CSCI 2911-A");
System.out.println("This program solves assignment SEPrep7g");
System.out.println("This program counts the number of words" +
" in a file and displays it\n");
int count = 0;
File file = new File("D:\\DICTION.TXT");
Scanner inputFile = new Scanner(file);
while(inputFile.hasNext())
{
count++;
}
inputFile.close();
System.out.println("There are "+count+" words in the file D:DICTION.TXT");
}
}
Here is the output.. it doesnt show the result. just stays there.
--------------------Configuration: SEPrep7g - JDK version 1.6.0_12 <Default> - <Default>--------------------
Program Results for CSCI 2911-A
This program solves assignment SEPrep7g
This program counts the number of words in a file and displays it
<----- it stays here.. never shows the result
Process interrupted by user.
can any1 see an error in my code?
EDIT: DICTION.TXT file has 3 words in it and the path is right.