I suggest you take a look at ZipFile.entries() .
Here is the code:
try (ZipFile zipFile = new ZipFile("test.zip")) { Enumeration zipEntries = zipFile.entries(); while (zipEntries.hasMoreElements()) { String fileName = ((ZipEntry) zipEntries.nextElement()).getName(); System.out.println(fileName); } }
If you are using Java 8 , you can avoid using the almost obsolete Enumeration class by using ZipFile::stream as follows:
zipFile.stream() .map(ZipEntry::getName) .forEach(System.out::println);
If you need to know if the entry is a directory or not, you can use ZipEntry.isDirectory . You cannot get much more information than without extracting the file (for obvious reasons).
If you want to not extract all the files, you can extract one file at a time using ZipFile.getInputStream for each ZipEntry . (Keep in mind that you do not need to store the decompressed data on disk, you can just read the input stream and discard the bytes in the process.
source share