Alexandre Borges
Alexandre Borges

Reputation: 87

How to programmatically see whats is inside a zip in android (without unzip)

I'm making an app for android and a need to check if the user's zip file entry is in the right format before unzip it, to avoid waste of time unziping. Could anyone help me?

PS.: I just need to know the name of the files inside the zip

Upvotes: 1

Views: 256

Answers (1)

Kirill Simonov
Kirill Simonov

Reputation: 8481

Use ZipFile: it uses random access to jump between file positions in the zip archive:

try (ZipFile file = new ZipFile("file.zip")) {
    final Enumeration<? extends ZipEntry> entries = file.entries();
    while (entries.hasMoreElements()) {
        final ZipEntry entry = entries.nextElement();
        System.out.println(entry.getName());
    }
}

Upvotes: 1

Related Questions