按行读取一个文件内容的方法 (ps:始终记不住读取步骤,so这次记录到博客中)
public List<String> readFileByLines(File file) throws IOException {
List<String> list = new ArrayList<String>();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
list.add(tempString.trim());
}
} catch (IOException e) {
log.error("readFileByLines", e);
} finally {
if (reader != null) {
reader.close();
}
}
return list;
}