只需阅读此文本文件并将每个单词放入a中
List,您就可以检查其中是否
List包含您的单词。
您可以使用
Scanner scanner=newScanner("FileNameWithPath");来读取文件,也可以尝试按照以下步骤向中添加单词List。
List<String> list=new ArrayList<>(); while(scanner.hasNextLine()){ list.add(scanner.nextLine()); }然后检查你的词是否存在
if(list.contains("yourWord")){ // found.}else{ // not found}顺便说一句,您也可以直接在文件中搜索。
while(scanner.hasNextLine()){ if("yourWord".equals(scanner.nextLine().trim())){ // found break; }else{ // not found } }


