(Java) List Files in a .zip
How to list files within a .zip Note: This example requires Chilkat v11.0.0 or greater.
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[])
{
boolean success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkZip zip = new CkZip();
success = zip.OpenZip("a.zip");
if (success == false) {
System.out.println(zip.lastErrorText());
return;
}
// Get the number of files and directories in the .zip
int n = zip.get_NumEntries();
CkZipEntry entry = new CkZipEntry();
int i = 0;
while (i < n) {
zip.EntryAt(i,entry);
if (entry.get_IsDirectory() == false) {
// (the filename may include a path)
System.out.println(entry.fileName());
}
i = i+1;
}
}
}
|