csv导出工具
import java.io.BufferedWriter;import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.List;
/**
* CSV操作(导出和导入)
*/
public class CsvUtils {
/**
* 导出
*
* @param os csv文件(路径+文件名),csv文件不存在会自动创建
* @param dataList 数据
* @return
*/
public static void exportCsv(OutputStream os, List<String[]> dataList) throws IOException {
OutputStreamWriter osw = null;
BufferedWriter bw = null;
osw = new OutputStreamWriter(os, "UTF-8");
bw = new BufferedWriter(osw);
if (dataList != null && !dataList.isEmpty()) {
for (String[] temp : dataList) {
for (int i = 0; i < temp.length; i++) {
bw.append(temp);
if (i != temp.length - 1) {
bw.append(",");
}
}
bw.append("\r\n");
}
}
if (bw != null) {
bw.close();
}
if (osw != null) {
osw.close();
}
}
}
CSV操作(导出和导入)
页:
[1]