Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

Unzip Encrypted Text into a String Variable

See more Zip Examples

Demonstrates how to open an encrypted .zip archive and unzip a text file directly into a string variable.

Chilkat Java Downloads

Chilkat2 Java
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();

        // Set the password required for decrypting.
        zip.setDecryptPassword("myPassword");

        try {
            zip.openZip("encrypted.zip");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Locate the file within the Zip to be unzipped into a string variable:
        ZipEntry entry = new ZipEntry();
        try {
            zip.entryMatching("*.csv", entry);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // lineEndingBehavior:
        // 0 = leave unchanged.
        // 1 = convert all to bare LF's
        // 2 = convert all to CRLF's
        int lineEndingBehavior = 0;
        String srcCharset = "utf-8";

        String strCsv = entry.unzipToString(lineEndingBehavior, srcCharset);
        System.out.println(strCsv);
    }
}