【文件属性】:
文件名称:文件内容读取类
文件大小:1KB
文件格式:JAVA
更新时间:2021-11-07 11:21:23
文件读取
public static List toFileString(String url) {
List wordList = new ArrayList<>();
InputStreamReader isr = null;
BufferedReader br = null;
try {
File file = new File(url);
isr = new InputStreamReader(new FileInputStream(file), "UTF-8");
br = new BufferedReader(isr);//构造一个BufferedReader类来读取文件
String s;
while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行
wordList.add(s.trim());
}
} catch (Exception e) {
Logger.getLogger(FileUtil.class).info(e);
return Collections.emptyList();
} finally {
try {
if (br != null) {
br.close();
}
if (isr != null) {
isr.close();
}
} catch (IOException e) {
Logger.getLogger(FileUtil.class).info(e);
}
}
return wordList;
}