TA的每日心情 | 擦汗 前天 09:15 |
---|
签到天数: 518 天 连续签到: 5 天 [LV.9]测试副司令
|
- 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[i]);
- if (i != temp.length - 1) {
- bw.append(",");
- }
- }
- bw.append("\r\n");
- }
- }
- if (bw != null) {
- bw.close();
- }
- if (osw != null) {
- osw.close();
- }
- }
- }
复制代码 CSV操作(导出和导入)
|
|