我有这段代码,运行程序时收到错误消息。我做错了什么吗?
import java.io.*;
import java.util.*;
public class countLines {
public static void main(String[] args) throws Exception {
int count = 0;
int word = 0;
File f = new File("file.txt");
Scanner input = new Scanner(f);
while(input.hasNext()){
String words = input.next();
word++;
}
while (input.hasNextLine()) {
input.nextLine();
count++;
}
input.close();
System.out.println("Number of Line: " + count);
System.out.println("This file has " + word + " words.");
}
}