无法在windows中使用ZipEntry从zip文件提取文件夹 java.util.zip.ZipInputStream zis=new java.util.zip.ZipInputStream(new BufferedInputStream(is)); java.util.zip.ZipEntry条目; 新文件(outdir+File.separator+changelog”).delete(); 新文件(outdir+File.separator+media”).delete(); 试一试{ 而((entry=zis.getNextEntry())!=null){ File of=新文件(outdir+File.separator+entry.getName()); if(entry.isDirectory()){ of.mkdirs(); 继续; }否则{ File xx=新文件(属于.getParent()); 如果(!xx.exists()){ 堆栈todo=新堆栈(); 做{ todo.push(xx.getAbsolutePath()); xx=新文件(xx.getParent()); }而(!xx.exists()); while(todo.size()>0){ xx=新文件(todo.pop()); 如果(!xx.exists()){ xx.mkdirs(); } } } } BufferedOutputStream bos=新BufferedOutputStream(新文件输出流(of),buffer.length); cpio(新的BufferedInputStream(zis),bos,“解压:”+entry.getName()); bos.flush(); bos.close(); } }捕获(IllegalArgumentException e){ //条目名称中的字符可能存在问题 }捕获(例外e){ System.out.println(e+“Srikanth”); } zis.close(); }

无法在windows中使用ZipEntry从zip文件提取文件夹 java.util.zip.ZipInputStream zis=new java.util.zip.ZipInputStream(new BufferedInputStream(is)); java.util.zip.ZipEntry条目; 新文件(outdir+File.separator+changelog”).delete(); 新文件(outdir+File.separator+media”).delete(); 试一试{ 而((entry=zis.getNextEntry())!=null){ File of=新文件(outdir+File.separator+entry.getName()); if(entry.isDirectory()){ of.mkdirs(); 继续; }否则{ File xx=新文件(属于.getParent()); 如果(!xx.exists()){ 堆栈todo=新堆栈(); 做{ todo.push(xx.getAbsolutePath()); xx=新文件(xx.getParent()); }而(!xx.exists()); while(todo.size()>0){ xx=新文件(todo.pop()); 如果(!xx.exists()){ xx.mkdirs(); } } } } BufferedOutputStream bos=新BufferedOutputStream(新文件输出流(of),buffer.length); cpio(新的BufferedInputStream(zis),bos,“解压:”+entry.getName()); bos.flush(); bos.close(); } }捕获(IllegalArgumentException e){ //条目名称中的字符可能存在问题 }捕获(例外e){ System.out.println(e+“Srikanth”); } zis.close(); },java,zip,extract,Java,Zip,Extract,entry.isDirectory()始终重试false,因此它正在创建文件而不是目录。问题出在哪里?ZipEntryfromZipInputStream表示文件末尾的空目录,其中包含\,包含元素的目录/ 因此,entry.isDirectory()不能使用空目录 其中,从ZipFile到ZipEntry工作正常。我认为ZipInputStream和ZipEntry行为之间存在差异。isDirectory对使用Windows标准选项“发送到/zip文件”压缩的文件根本不起作用 zip的格式与7z

entry.isDirectory()始终重试false,因此它正在创建文件而不是目录。问题出在哪里?

ZipEntryfromZipInputStream表示文件末尾的空目录,其中包含\,包含元素的目录/

因此,entry.isDirectory()不能使用空目录


其中,从ZipFileZipEntry工作正常。我认为ZipInputStream和ZipEntry行为之间存在差异。

isDirectory对使用Windows标准选项“发送到/zip文件”压缩的文件根本不起作用


zip的格式与7zip或Winzip等工具生成的格式不同。(很高兴有一个标准的归档压缩:D)

我不确定ZipInputStream和ZipEntry之间的区别,但我认为您对路径的表示方式有所了解。请参阅此错误报告:()。
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();

}