我如何将代码中的 befferedreader 更改为 Scanner,因为我不允许使用 BufferedReader?还是有可能?
public static void Option3Method() throws IOException
{
FileReader fr = new FileReader("wordlist.txt");
BufferedReader br = new BufferedReader(fr);
String s;
String words[]=new String[500];
String word = JOptionPane.showInputDialog("Enter a word to search for");
while ((s=br.readLine())!=null)
{
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");}
}
fr.close();
}
}