Java Utililty Methods Zip File

List of utility methods to do Zip File

Description

The list of methods to do Zip File are organized into topic(s).

Method

voidzip(File path)
zip
zip(path.getAbsolutePath(), path.getAbsolutePath());
voidzip(File source, File target)
zip
final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(target));
zip("", source, out);
out.close();
voidzip(File source, File target)
zip
zip(source, target, false);
voidzip(File sourceDir, OutputStream targetStream)
zip
if (!sourceDir.isFile() && !sourceDir.isDirectory()) {
    return;
final ZipOutputStream cpZipOutputStream = new ZipOutputStream(targetStream);
cpZipOutputStream.setLevel(9);
zipFiles(sourceDir, sourceDir, cpZipOutputStream);
cpZipOutputStream.finish();
cpZipOutputStream.close();
...
voidzip(File src, File target)
zip a folder to a file
zip(src, null, target, ALL_FILES);
voidzip(File srcDir, File zipFile)
Create a zip from the specified directory.
mkdir(parent(zipFile));
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
try {
    File[] kids = list(srcDir);
    for (int i = 0; kids != null && i < kids.length; ++i)
        zip(kids[i], "", out);
} finally {
    out.close();
...
voidzip(File srcDirectory, File destFile)
Zips a directory
zip(srcDirectory, destFile, false);
voidzip(File srcFile, File destFile, String archiveRoot)
Zip a file or a directory.
FileOutputStream fout = new FileOutputStream(destFile);
try {
    zip(srcFile, fout, archiveRoot);
} finally {
    fout.close();
voidzip(File theFileToZip)
zip
byte[] buf = new byte[8096];
File zipFile = new File(theFileToZip.getParent(), theFileToZip.getName() + ".zip");
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile))) {
    try (FileInputStream fis = new FileInputStream(theFileToZip)) {
        zos.putNextEntry(new ZipEntry(theFileToZip.getName()));
        int lenght;
        while ((lenght = fis.read(buf)) > 0) {
            zos.write(buf, 0, lenght);
...
voidzip(File toZip, File outFile)
Zips the specified file or folder
ZipOutputStream out = null;
try {
    out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
    byte[] data = new byte[BUF_SIZE];
    ArrayList<File> listToZip = new ArrayList<File>();
    listToZip.add(toZip);
    while (listToZip.size() > 0) {
        File file = listToZip.remove(0);
...