2 回答

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊
嘗試BufferedReader,我嘗試并為我工作(我刪除了一些無(wú)用的行)。在您的使用中,您從文件中讀取所有字節(jié),會(huì)有額外的字節(jié)。
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貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊
嘗試BufferedReader,我嘗試并為我工作(我刪除了一些無(wú)用的行)。在您的使用中,您從文件中讀取所有字節(jié),會(huì)有額外的字節(jié)。
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());
}
}
添加回答
舉報(bào)