使用JavaCSV写入csv文件

//需写入的csv文件
String src = "F:/csv/test.csv";

CsvWriter csvWriter = new CsvWriter(src, ',', Charset.forName("UTF-8"));
//设置列头
String[] csvHeaders = {"姓名","年龄","性别"};
//写入cvs文件
csvWriter.writeRecord(csvHeaders);
for(int i=0;i<30;i++){
	//循环写入内容
	String[] csvContent = {"姓名"+i,"年龄"+i,"性别"+i};
	csvWriter.writeRecord(csvContent);
}
csvWriter.close();

你可能感兴趣的:(Java)