闲来无事,写了个java按行读取txt文件的小方法
/**
* 按行读取txt中内容,保存在list中
* @param strPath
* @return
* @throws IOException
*/
public static ArrayList<String> GetTextDataByLine(String strPath)
throws IOException {
ArrayList<String> listResult = new ArrayList<String>();
BufferedReader bw = new BufferedReader(new InputStreamReader(
new FileInputStream(strPath), "gbk"));
String line = null;
// 因为不知道有几行数据,所以先存入list集合中
while ((line = bw.readLine()) != null) {
listResult.add(line);
}
bw.close();
return listResult;
}