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

Create Password Protected Zip containing a Single File.

See more Zip Examples

Create a password-protected .zip containing a single file. (This uses the older Zip 2.0 encryption scheme, which is weaker and not as secure as AES encryption, which Chilkat Zip also supports.)

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Zip;

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.newZip("test.zip");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

ERROR: Method not in Chilkat2 Java: Zip.SetPassword
        zip.ERROR();
        zip.setPasswordProtect(true);

        boolean saveExtraPath = false;
        zip.addFile("/temp/hamlet.xml", saveExtraPath);

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

        System.out.println("Zip Created!");
    }
}