簡體   English   中英

無法在Windows中使用ZipEntry從zip文件中提取文件夾

[英]Unable to extract folders from zip file using ZipEntry in windows

java.util.zip.ZipInputStream zis = new java.util.zip.ZipInputStream(new BufferedInputStream(is));

    java.util.zip.ZipEntry entry;
    new File(outdir+ File.separator+"changelog").delete();
    new File(outdir+ File.separator+"media").delete();
    try {
        while ((entry = zis.getNextEntry()) != null) {

            File of = new File(outdir + File.separator + entry.getName());

            if (entry.isDirectory()) {
                of.mkdirs();
                continue;
            } else {
                File xx = new File(of.getParent());
                if (!xx.exists()) {
                    Stack<String> todo = new Stack<String>();
                    do {
                        todo.push(xx.getAbsolutePath());
                        xx = new File(xx.getParent());
                    } while (!xx.exists());
                    while (todo.size() > 0) {
                        xx = new File(todo.pop());
                        if (!xx.exists()) {
                            xx.mkdirs();
                        }
                    }
                }
            }

            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(of), buffer.length);

            cpio(new BufferedInputStream(zis), bos, "unzip:" + entry.getName());

            bos.flush();
            bos.close();
        }
    } catch (IllegalArgumentException e) {
        // problem with chars in entry name likely
    }catch(Exception e){
        System.out.println(e+"Srikanth");
    }
    zis.close();

}

entry.isDirectory()始終重設false,因此它將創建文件而不是目錄。 問題是什么?

ZipInputStream中的 ZipEntry表示文件末尾帶有\\的空目錄,目錄帶有/的元素

因此, entry.isDirectory()無法與空目錄一起使用。

ZipFile那里作為ZipEntry可以正常工作。 我認為ZipInputStreamZipEntry行為之間存在差異。

isDirectory對於使用Windows標准選項“發送到/壓縮文件”壓縮的文件根本不起作用

zip的格式與使用7zip或Winzip之類的工具生成的格式不同。 (不錯,有一個標准的壓縮包:D)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM