BufferedReader导入踩坑
作者:互联网
我在做读取后缀文件踩坑
public List<Object> txtOrCsvOrExport(MultipartFile file) {
List<Object> linList = new ArrayList<>();
InputStream is = null;
try {
is = file.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));//GBK
String s = "";
while((s = reader.readLine())!=null){
linList.add(s);
}
<!-- 千万不要写成下面这种:以下面的图片为例while循环中的reader.readLine读取到的是0.444添加中的时候读取到的是0.44
while(reader.readLine()!=null){
linList.add(reader.readLine());
}
--!>
reader.close();
} catch (Exception e){
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return linList;
}
标签:printStackTrace,BufferedReader,导入,linList,reader,new,readLine,null 来源: https://www.cnblogs.com/shuoya/p/15480577.html