(Java) List Files in a .zip
How to list files within a .zip
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkZip zip = new CkZip();
boolean success = zip.OpenZip("a.zip");
if (success != true) {
System.out.println(zip.lastErrorText());
return;
}
int n;
// Get the number of files and directories in the .zip
n = zip.get_NumEntries();
System.out.println(n);
CkZipEntry entry;
int i;
for (i = 0; i <= n - 1; i++) {
entry = zip.GetEntryByIndex(i);
if (entry.get_IsDirectory() == false) {
// (the filename may include a path)
System.out.println(entry.fileName());
}
}
}
}
|