java 为 CSV 文件创建标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41930398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 06:15:28  来源:igfitidea点击:

Creating headers for CSV file

javaandroidopencsv

提问by iam user

I'm writing a CSV file using the Opencsvlibrary and need to add headers to my file. The file is created and the headers are inserted, but all the headers in same cell.

我正在使用Opencsv库编写一个 CSV 文件,需要向我的文件添加标题。创建文件并插入标题,但所有标题都在同一个单元格中

csvFile.createNewFile();
CSVWriter csvWrite = new CSVWriter(new FileWriter(csvFile));
String heading = "eid,name,vid,emp_id,balance_amt,handover_to,entry_date \n";
csvWrite.writeNext(new String[]{heading});

回答by Deepak Kumar

Here is your solution :

这是您的解决方案:

 CSVWriter csvWrite = new CSVWriter(new FileWriter(csvFile));
 String[] entries = {"eid","name","vid","emp_id","balance_amt","handover_to","entry_date"};
 csvWrite.writeNext(entries);

thats working fine here ! try

这在这里工作正常!尝试