In this example we are going to see How to List The Contents Of Zip File In Java.
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class JavaZipFileContent { public static void main(String[] args) throws Exception { ZipFile zipFile = new ZipFile("testfile.zip"); Enumeration zipEntries = zipFile.entries(); while (zipEntries.hasMoreElements()) { System.out.println(((ZipEntry) zipEntries.nextElement()).getName()); } } } |
Using zipFile.entries, we will get all the zip entries as Enumeration and by using iteration we can print name of the file.