Small Open Source Java Tools and Libraries

ZIP directory

Compress a complete directory and it's subdirectories with a single line of code using Utils4J Internal link outside layout:
// Given a local directory "mydir" on drive "c:" that contains
// three files "x.txt", "y.txt" and "z.txt"
File dirToZip = new File("c:/mydir");

// Run the ZIP command
Utils4J.zipDir(dirToZip, "abc/def", new File("c:/myfile1.zip"));
// The archive will contain the following structure:
// abc/def/x.txt
// abc/def/y.txt
// abc/def/z.txt

// Run the ZIP command again
Utils4J.zipDir(dirToZip, "", new File("c:/myfile2.zip"));
// The second archive will contain the following structure:
// x.txt
// y.txt
// z.txt

You can find a full example here Internal link outside layout (Package "org.fuin.examples.utils4j").