Java Utililty Methods Zip Directory

List of utility methods to do Zip Directory

Description

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

Method

voidzipDirectory(File root, File directory, ZipOutputStream zos)
Zip directory.
for (File item : directory.listFiles()) {
    if (item.isDirectory()) {
        zipDirectory(root, item, zos);
    } else {
        byte[] readBuffer = new byte[2156];
        int bytesIn;
        FileInputStream fis = new FileInputStream(item);
        String path = item.getAbsolutePath().substring(root.getAbsolutePath().length() + 1);
...
voidzipDirectory(File srcDir, File destFile)
Zip the content of the specified directory to the specified zip file.
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destFile));
assert srcDir.isDirectory();
File rootDir = srcDir.getAbsoluteFile();
for (File f : srcDir.listFiles()) {
    addFileToZip(zos, f, rootDir);
zos.close();
voidzipDirectory(File zipDir, ZipOutputStream zos)
ZIP a directory with sub-folders and write it to the given output stream.
zipDirectory(zipDir, zos, "");
StringzipDirectory(final String sourceFolder, final String targetFolder, final String zipExtension)
Creates a zip file to the specified location
File directoryToZip = new File(sourceFolder);
List<File> fileList = new ArrayList<File>();
System.out.println("---Getting references to all files in: " + directoryToZip.getCanonicalPath());
getAllFiles(directoryToZip, fileList);
System.out.println("---Creating zip file");
String zippedfile = writeZipFile(directoryToZip, fileList, targetFolder, zipExtension);
if (zippedfile.isEmpty())
    System.out.println("----Failed to zip the direstory: " + directoryToZip);
...
voidzipDirectory(String dbDumpPath)
zip Directory
FileOutputStream fileOutputStream = new FileOutputStream(dbDumpPath + ".zip");
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
File dumpDirectory = new File(dbDumpPath);
addDirectory(zipOutputStream, dumpDirectory);
zipOutputStream.close();
voidzipDirectory(String dir2zip, ZipOutputStream zos, String zipPath)
zip Directory
File zipDir = new File(dir2zip);
String[] dirList = zipDir.list();
byte[] readBuffer = new byte[2156];
int bytesIn = 0;
for (int i = 0; i < dirList.length; i++) {
    File f = new File(zipDir, dirList[i]);
    if (f.isDirectory()) {
        String filePath = f.getPath();
...
voidzipDirectory(String directoryName, int iBaseFolderLength, ZipOutputStream zos, CRC32 crc)
Add the given directory into the zipStream.
File dirobject = new File(directoryName);
if (dirobject.exists()) {
    if (dirobject.isDirectory()) {
        File[] fileList = dirobject.listFiles();
        for (int i = 0; i < fileList.length; i++) {
            if (fileList[i].isDirectory()) {
                zipDirectory(fileList[i].getPath(), iBaseFolderLength, zos, crc);
            } else if (fileList[i].isFile()) {
...
voidzipDirectory(String directoryName, String targetName)
zip Directory
try {
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(targetName + ".zip"));
    zipDir(directoryName, zos);
    zos.close();
} catch (Exception e) {
    e.printStackTrace(System.out);
voidzipDirectory(String dirName, String zipFileName)
Zips a directory into a zip-archive
try {
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFileName));
    zipDirectory(dirName, zos, "");
    zos.close();
} catch (Exception ex) {
    throw new RuntimeException("Error saving project files (zip)", ex);
voidzipDirectory(ZipOutputStream out, String stripPath, File dir, char pathSeparator)
Uses code fragments from Jakarta-Ant, Copyright: Apache Software Foundation.
String[] entries = dir.list();
if (entries == null || entries.length == 0) {
    return;
for (String entry : entries) {
    File file = new File(dir, entry);
    if (file.isDirectory()) {
        zipDirectory(out, stripPath, file, pathSeparator);
...