I'm trying to generate and download csv file in a Java project that use an old framework called Echo Studio 3, with Tomcat.
here is my code:
List<Object> reportCount = this.getReport(accountId);
ArrayList<String[]> result = new ArrayList<String[]>();
for (Object list: reportCount) {
String[] rowReport = (String[]) list;
result.add(new String[]{String.valueOf(rowReport[0]),String.valueOf(rowReport[1])});
}
File filename = new File("report.csv");
FileWriter fw = new FileWriter(filename);
fw.append("Name");
fw.append(',');
fw.append("Count");
fw.append('\n');
for (String[] ls: result){
fw.append(ls[0].toString());
fw.append(',');
fw.append(ls[1].toString());
fw.append('\n');
}
try {
fw.flush();
fw.close();
} catch (Exception e) {
System.out.println("Error while flushing/closing fileWriter !!!");
e.printStackTrace();
}
When the code is triggered, nothing happens, and i have no error message. when i run the debug mode, the result is filled with data, and the breakpoint pass throw the flush(), and no error, and the client is not getting the generated file, did I miss something?