Creating headers for CSV file

iam user picture iam user · Jan 30, 2017 · Viewed 15.3k times · Source

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

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});

Answer

Deepak Kumar picture Deepak Kumar · Jan 30, 2017

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