/**
* CSV文件生成方法
* @param head表单头
* @param dataList表单内容
* @param outPutPath输出路径
* @param filename表单文件名
* @return
*/
public static File createCSVFile(List<Object> head, List<List<Object>> dataList,String outPutPath, String filename) {
File csvFile = null;
BufferedWriter csvWtriter = null;
try {
csvFile = new File(outPutPath + File.separator + filename + ".csv");
File parent = csvFile.getParentFile();
FileOutputStream fos = new FileOutputStream(csvFile);
// 写入bom头
byte[] uft8bom={(byte)0xef,(byte)0xbb,(byte)0xbf};
fos.write(uft8bom);
if (parent != null && !parent.exists()) {
parent.mkdirs();
}
csvFile.createNewFile();
// GB2312使正确读取分隔符",
java导出csv内容乱码
最新推荐文章于 2023-02-13 10:11:13 发布
由于Java导出的CSV文件不包含BOM头,导致在某些软件中打开时出现汉字乱码。通过在文件开头添加UTF-8的BOM字符(EF BB BF)可以解决此问题。解决方案是在写入文件前,先写入BOM头。
摘要由CSDN通过智能技术生成