I am preparing a reporting for all the data in excel using apache poi and then getting it downloaded using ByteArrayOutputStream.If I download the file it gets downloaded, when I download some other file , the previous file data comes with new downloaded file. I don't know if data is saved or what
inputStream.close();
FileOutputStream file1 = new FileOutputStream(new File(file.getAbsolutePath()));
workbook.write(file1);
file1.close();
FileInputStream designedFile = new FileInputStream(new File(file.getAbsolutePath()));
byte[] buf = new byte[(int) file.length()];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(buf, 0, designedFile.read(buf));
baos.close();
baos.flush();
workbook.close();
designedFile.close();
response.setContentType("application/*");
response.setHeader("Content-Disposition", "attachment; filename=" + res + "." + extension);
DownloadUtility.downloadxlsxWithName(response, buf, res);