2 回答
TA贡献1735条经验 获得超5个赞
尝试BufferedReader,我尝试并为我工作(我删除了一些无用的行)。在您的使用中,您从文件中读取所有字节,会有额外的字节。
public class LocalDictionary {
private ArrayList<String> wordsSet = new ArrayList<>();
public LocalDictionary() throws Exception {
//dont forget to absolute path to here. click righ click to file and copy path
File file = new File("C:\\Users\\higuys\\IdeaProjects\\try\\src\\words.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null)
//trim and tolowercase and add to list.
wordsSet.add(line.trim().toLowerCase());
}
public boolean contains(String word) {
return wordsSet.contains(word.toLowerCase());
}
}
TA贡献1898条经验 获得超8个赞
尝试BufferedReader,我尝试并为我工作(我删除了一些无用的行)。在您的使用中,您从文件中读取所有字节,会有额外的字节。
public class LocalDictionary {
private ArrayList<String> wordsSet = new ArrayList<>();
public LocalDictionary() throws Exception {
//dont forget to absolute path to here. click righ click to file and copy path
File file = new File("C:\\Users\\higuys\\IdeaProjects\\try\\src\\words.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null)
//trim and tolowercase and add to list.
wordsSet.add(line.trim().toLowerCase());
}
public boolean contains(String word) {
return wordsSet.contains(word.toLowerCase());
}
}
添加回答
举报