I am stuck with an issue where I need to export data to a .csv file, but not store the file in file system - instead I need to simply open the file in browser.
I have written the below code to write data to .csv file:
FileWriter myWriter = new FileWriter("output.csv");
myWriter.append(EmployeeCode);
myWriter.append(',');
myWriter.append(Band);
myWriter.append('\n');
response.setHeader("Content-Disposition", "attachment; filename=output.csv");
response.setContentType("application/ms-excel");
response.setCharacterEncoding("UTF-8");
I am able to open a .csv file but it is empty. My data does not get populated into it. Please suggest what am I doing wrong.
myWriter.flush();myWriter.close();
& while writing print the same data on screenSystem.out.println(EmployeeCode + "==" + Band);
and see actually you are getting data or not. – ComamyWriter.flush();myWriter.close();
and let me know what you get? – Coma