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