Java Requires Chilkat v11.0.0+
Chilkat2 Java
Iterate over Matching Filenames
See more Zip Examples
Iterates over files within a .zip that match a pattern. In this case, the pattern is "*.pem". This example will open a .zip containing files of type .txt, .cer, .pem, and possibly others, and will iterate over only the .pem files.Chilkat Java Downloads
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 requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Zip zip = new Zip();
// Open a .zip containing PEM files, among other things..
try {
zip.openZip("qa_data/certs/thawte-roots.zip");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
ZipEntry entry = new ZipEntry();
String pemStr = "";
String pattern = "*.pem";
boolean bHasMoreMatches;
try {
zip.entryMatching(pattern, entry);
bHasMoreMatches = true;
} catch (ChilkatException e) {
bHasMoreMatches = false;
}
while (bHasMoreMatches) {
System.out.println("Entry: " + entry.getFileName());
// Get the uncommpressed contents of the entry:
pemStr = entry.unzipToString(0, "utf-8");
System.out.println(pemStr);
bHasMoreMatches = entry.getNextMatch(pattern);
}
}
}