From 74a6d38d24252cb74327e837e8ca266d46ae240f Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 22 Sep 2018 21:09:23 +0300 Subject: [PATCH] fix for zip empty dir --- .../src/main/java/com/baeldung/zip/ZipDirectory.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core-java-io/src/main/java/com/baeldung/zip/ZipDirectory.java b/core-java-io/src/main/java/com/baeldung/zip/ZipDirectory.java index 7da71a093d..42147b07db 100644 --- a/core-java-io/src/main/java/com/baeldung/zip/ZipDirectory.java +++ b/core-java-io/src/main/java/com/baeldung/zip/ZipDirectory.java @@ -24,6 +24,13 @@ public class ZipDirectory { return; } if (fileToZip.isDirectory()) { + if (fileName.endsWith("/")) { + zipOut.putNextEntry(new ZipEntry(fileName)); + zipOut.closeEntry(); + } else { + zipOut.putNextEntry(new ZipEntry(fileName + "/")); + zipOut.closeEntry(); + } final File[] children = fileToZip.listFiles(); for (final File childFile : children) { zipFile(childFile, fileName + "/" + childFile.getName(), zipOut);