テキストファイル内の単語を検索するこの方法がありますが、単語が存在する場合でも常に否定的な結果が返されますか??
public static void Option3Method(String dictionary) throws IOException
{
Scanner scan = new Scanner(new File(dictionary));
String s;
int indexfound=-1;
String words[] = new String[500];
String word1 = JOptionPane.showInputDialog("Enter a word to search for");
String word = word1.toLowerCase();
word = word.replaceAll(",", "");
word = word.replaceAll("\\.", "");
word = word.replaceAll("\\?", "");
word = word.replaceAll(" ", "");
while (scan.hasNextLine()) {
s = scan.nextLine();
indexfound = s.indexOf(word);
}
if (indexfound>-1)
{
JOptionPane.showMessageDialog(null, "Word found");
}
else
{
JOptionPane.showMessageDialog(null, "Word not found");
}