How to check if a generated zip file is corrupted?

后端 未结 8 1691
梦毁少年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:38

    You can use the ZipFile class to check your file :

     static boolean isValid(final File file) {
        ZipFile zipfile = null;
        try {
            zipfile = new ZipFile(file);
            return true;
        } catch (IOException e) {
            return false;
        } finally {
            try {
                if (zipfile != null) {
                    zipfile.close();
                    zipfile = null;
                }
            } catch (IOException e) {
            }
        }
    }
    

提交回复
热议问题