0

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);
        
Anjum
  • 1
  • 2
    I don't understand your question, can you please add some more information. – sorifiend Apr 06 '22 at 05:22
  • Why do you hand over the buffer `byte[] buf` to your `DownloadUtility`? Shouldn't that be `DownloadUtility.downloadxlsxWithName(response, baos.toByteArray(), res);`? And for how to convert `InputStream` to byte array in Java see https://stackoverflow.com/questions/1264709/convert-inputstream-to-byte-array-in-java. – Axel Richter Apr 06 '22 at 07:52

0 Answers0