我正在使用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});
答案 0 :(得分:4)
以下是您的解决方案:
CSVWriter csvWrite = new CSVWriter(new FileWriter(csvFile));
String[] entries = {"eid","name","vid","emp_id","balance_amt","handover_to","entry_date"};
csvWrite.writeNext(entries);
多数民众赞成在这里运作良好!试试
答案 1 :(得分:0)
如果要使用FileWriter,可以使用:
FileWriter writer = new FileWriter(CSV_LOCATION);
writer.append("Name,Age,Company,Salary");
writer.append("\n");