このコードがあり、プログラムを実行するとエラーが発生します。私はこれで何か間違ったことをしていますか?
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.");
}
}