In this example we are going to see how to to Zip a Folder in Java.
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import java.io.IOException; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class JavaZipEntryIsDirectory { public static void main(String args[]) { try { ZipFile zipFile = new ZipFile("c:/File/Files.zip"); Enumeration enumeration = zipFile.entries(); System.out.print("File Name"); System.out.print("\t\t\t\tIs Directory"); System.out.print("\n---------------------------------\n"); while (enumeration.hasMoreElements()) { ZipEntry entry = (ZipEntry) enumeration.nextElement(); String entryName = entry.getName(); boolean isDir = entry.isDirectory(); System.out.print(entryName); System.out.print("\t\t\t\t" + isDir); System.out.print("\n"); } zipFile.close(); } catch (IOException ioe) { System.out.println("Error opening zip file" + ioe); } } |
Zip Entry Is Directory Example , Java