我正在编写一个方法来搜索列表形式的单词文本文件,对于由用户输入但由程序输入的单词将返回肯定的结果,如果一个字母在所有被发现,例如,如果我搜索“F”,它将返回有在字典中的单词“F”时,有没有正在搜索一个文本文件
public static void Option3Method(String dictionary) throws IOException {
Scanner scan = new Scanner(new File("wordlist.txt"));
String s;
String words[] = new String[500];
String word = JOptionPane.showInputDialog("Enter a word to search for");
while (scan.hasNextLine()) {
s = scan.nextLine();
int indexfound = s.indexOf(word);
if (indexfound > -1) {
JOptionPane.showMessageDialog(null, "Word was found");
} else if (indexfound < -1) {
JOptionPane.showMessageDialog(null, "Word was not found");
}
}
}