나는이 방법을 사용하여 텍스트 파일에서 단어를 검색하지만 지속적으로 부정적인 결과를 돌려 준다.자바 텍스트 파일 검색
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");
}