Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

List Files in Zip using EntryAt / GetNext

See more Zip Examples

Demonstrates how to iterate over the files and directories in a zip archive using EntryAt/GetNext.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Zip;
import com.chilkatsoft.chilkat2.ZipEntry;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example assumes the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Zip zip = new Zip();

        try {
            zip.openZip("qa_data/zips/xml_files.zip");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        ZipEntry entry = new ZipEntry();
        boolean hasMoreEntries;
        try {
            zip.entryAt(0, entry);
            hasMoreEntries = true;
        } catch (ChilkatException e) {
            hasMoreEntries = false;
        }
        while (hasMoreEntries) {
            if (!entry.getIsDirectory()) {
                System.out.println(entry.getFileName());
            } else {
                System.out.println("(directory) " + entry.getFileName());
            }

            hasMoreEntries = entry.getNext();
        }

        // Sample output showing both file and directory entries:

        // a1.xml
        // b1.xml
        // c1.xml
        // (directory) dir1/
        // dir1/a2.xml
        // dir1/c2.xml
        // (directory) dir2/
        // (directory) dir2/dir3/
        // dir2/dir3/c3.xml
    }
}