で引っ張ったテキストファイルをスキャナーで読み取ろうとしていますJFileChooser
。はwordCount
正常に動作しているので、読み取りが行われていることがわかります。ただし、ユーザーが入力した単語のインスタンスを検索することはできません。
public static void main(String[] args) throws FileNotFoundException {
String input = JOptionPane.showInputDialog("Enter a word");
JFileChooser fileChooser = new JFileChooser();
fileChooser.showOpenDialog(null);
File fileSelection = fileChooser.getSelectedFile();
int wordCount = 0;
int inputCount = 0;
Scanner s = new Scanner (fileSelection);
while (s.hasNext()) {
String word = s.next();
if (word.equals(input)) {
inputCount++;
}
wordCount++;
}