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
If you want to use FileWriter you can make use of:
FileWriter writer = new FileWriter(CSV_LOCATION);
writer.append("Name,Age,Company,Salary");
writer.append("\n");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With