code sample
- import file content by BufferedReader
File stopWords = new File("data/stopWords.gold");
BufferedReader bReader = new BufferedReader(new FileReader(stopWords));
String fileString = "";
String lineString = bReader.readLine();
while (lineString != null) {
fileString += lineString;
lineString = bReader.readLine();
}
bReader.close();
- import file content by Scanner and process it
private void checkWords() {
File file = getInputFileNameFromUser();
try {
Scanner scanner = new Scanner(file);
scanner.useDelimiter("[^a-zA-Z]+");
while (scanner.hasNext()) {
String tk = scanner.next();
tk = tk.toLowerCase();
if (!dictionaryHashSet.contains(tk)) {
// System.out.println(tk + " is not in the dictionary.");
corrections(tk.toLowerCase(), dictionaryHashSet);
}
}
scanner.close();
} catch (FileNotFoundException e) {
// TODO: handle exception
System.out.println(e.getMessage());
}
}
作者 @FL
2019 年 04月 24日