How to check if a generated zip file is corrupted?

后端 未结 8 1673
梦毁少年i
梦毁少年i 2020-12-05 10:33

we have a piece of code which generates a zip file on our system. Everything is ok, but sometimes this zip file while opened by FilZip or WinZip is considered to be corrupte

相关标签:
8条回答
  • 2020-12-05 10:54

    ZipOutputStream does not close the underlying stream.

    What you need to do is:

    FileOutputStream fos = new FileOutputStream(...);
    ZipOutputStream zos = new ZipOutputStream(fos);
    

    Then in your closing block:

    zos.close();
    fos.flush(); // Can't remember whether this is necessary off the top of my head!
    fos.close();
    
    0 讨论(0)
  • 2020-12-05 11:03

    Your code is basically OK, try to find out which file is responsible for the corrupted zip file. Check whether digitalFile.getFile() always returns a valid and accessible argument to FileInputStream. Just add a bit logging to your code and you will find out what's wrong.

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