How to send zip file without creating it on physical location?

前端 未结 2 730
情歌与酒
情歌与酒 2021-02-08 20:29

I want to send email with zip file attachment.. I m able to send pdf files without saving them on physical location using ByteArrayOutputStream. But when I try zip those file an

相关标签:
2条回答
  • 2021-02-08 20:52

    You forgot to call zos.closeEntry() after each item is written, at the end of your for loop. And as noted, you haven't closed your ZipOutputStream.

    I don't think you need to call entry.setSize(), either.

    Otherwise, this should work.

    0 讨论(0)
  • 2021-02-08 21:09

    I think that you have not flushed and closed ZipOutputStream. Try to call zos.flush(); zos.close(). I hope this will help.

    If not try to extract byte array from your ByteArrayOutputStream, save it into file and open with zip-enable tool. It is just for debugging to be sure that your ZIP is OK and is not corrupted.

    0 讨论(0)
提交回复
热议问题