/**
* 导出csv文件工具
* @param file 文件路径+文件名称.csv
* @param dataList 需要导出csv的数据
* @return
*/
public static boolean exportCsv(File file, List<String> dataList) {
boolean isSucess = false;
FileOutputStream out = null;
OutputStreamWriter osw = null;
BufferedWriter bw = null;
try {
out = new FileOutputStream(file);
out.write(new byte []{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});//解决中文乱码问题
osw = new OutputStreamWriter(out);
bw = new BufferedWriter(osw);
if (dataList != null && !dataList.isEmpty()) {
for (String data : dataList) {
bw.append(data).append("\r");
}
}
isSucess = true;
} catch (IOException e) {
e.printStackTrace();
} finally { //释放资源:先开后关原则
try {
if (bw != null) {
bw.close();
}
if (osw != null) {
osw.close();
}
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return isSucess;
}
导出csv文件工具方法
最新推荐文章于 2024-08-27 10:41:38 发布