java csv文件写入

List<String> list_code = null;

方案1 控制字符集:

BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName),"Shift_JIS"));
CSVPrinter printer = new CSVPrinter(bw, CSVFormat.EXCEL);

方案2 默认字符集utf8:
CSVPrinter printer = new CSVPrinter(new FileWriter(fileName),CSVFormat.EXCEL);

写入

printer.printRecord("id", "userName", "firstName", "lastName", "birthday");
printer.printRecord(list_code);
//bw.close();
printer.close();

猜你喜欢

转载自www.cnblogs.com/atq999/p/12376889.html
今日推荐