Unzip process works on one zip while it doesnt on another?

ぐ巨炮叔叔 提交于 2019-12-24 07:03:30

问题


I've been trying to understand why my code doesnt work on a zip and it doesnt on another..
THIS zip unzips , and THIS zip doesnt Here is the code I use:

String zipFile = Path + FileName;


            FileInputStream fin = new FileInputStream(zipFile);
            ZipInputStream zin = new ZipInputStream(fin);

            ZipEntry ze = null;
            while ((ze = zin.getNextEntry()) != null) {
                UnzipCounter++;
                if (ze.isDirectory()) {
                    dirChecker(ze.getName());
                } else {
                    FileOutputStream fout = new FileOutputStream(Path
                            + ze.getName());
                    while ((Unziplength = zin.read(Unzipbuffer)) > 0) {
                        fout.write(Unzipbuffer, 0, Unziplength);                    
                    }
                    zin.closeEntry();
                    fout.close();

                }

            }
            zin.close();

Can anyone tell me why?

The zip doesnt work means that when it reaches the line "while ((ze = zin.getNextEntry()) != null) {".. ze is always null so it doesnt enter the loop so it doesnt extract anything.. I can open+unzip both files with WinRar..


回答1:


Here's the actual error:

java.io.EOFException
    at java.io.RandomAccessFile.readFully(RandomAccessFile.java:383)
    at gnu.java.util.zip.ZipFile$PartialInputStream.fillBuffer(ZipFile.java:647)

Looks like your zip file is corrupt. WinRAR tends to ignore some kinds of corruption.

This is a personal gripe of mine - I believe it would be better if tools didn't do that sort of thing, because it means that whoever created the zip file probably doesn't know about the corruption either, and when you tell them, they will be all like, "but it isn't, look .. it opens in [insert broken app here]."



来源:https://stackoverflow.com/questions/7589609/unzip-process-works-on-one-zip-while-it-doesnt-on-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!