Java Requires Chilkat v11.0.0+
Chilkat2 Java
Unzip Text File to String
See more Zip Examples
Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable.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();
try {
zip.openZip("qa_data/zips/EC16100.zip");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Get the 1st file in the .zip
ZipEntry entry = new ZipEntry();
try {
zip.entryAt(0, entry);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
String fileContents = entry.unzipToString(0, "utf-8");
System.out.println(fileContents);
}
}