Java Utililty Methods Zip Folder

List of utility methods to do Zip Folder

Description

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

Method

voidaddFolderToZip(File folder, String parentFolderName, ZipOutputStream zip)
Recursively adds the contents of the specified File representing a folder to the specified ZipOutputStream .
String parent = parentFolderName == null || parentFolderName.trim().isEmpty() ? ""
        : parentFolderName.trim() + "/";
if (folder.exists()) {
    File[] files = folder.listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.isDirectory()) {
                addFolderToZip(file, parent + file.getName(), zip);
...
voidaddFolderToZip(String folderPath, ZipOutputStream out)
Adds a new entry to the zip file corresponding to a new folder.
out.putNextEntry(new ZipEntry(folderPath + "/"));
voidaddFolderToZip(String path, File srcFolder, ZipOutputStream zip)
add Folder To Zip
if (srcFolder.list().length == 0) {
    addFileToZip(path, srcFolder, zip, true);
} else {
    for (File file : srcFolder.listFiles()) {
        if (path.equals("")) {
            addFileToZip(srcFolder.getName(), file, zip, false);
        } else {
            addFileToZip(path + "/" + srcFolder.getName(), file, zip, false);
...
voidaddFolderToZip(String path, File srcFolder, ZipOutputStream zip, String destZipFile)
add Folder To Zip
for (String fileName : srcFolder.list()) {
    if (path.equals("")) {
        addFileToZip("/", new File(srcFolder, fileName), zip, destZipFile);
    } else {
        addFileToZip(srcFolder.getName(), new File(srcFolder, fileName), zip, destZipFile);
voidaddFolderToZip(String path, String srcFolder, ZipOutputStream zip)
add Folder To Zip
File folder = new File(srcFolder);
String fileListe[] = folder.list();
try {
    int i = 0;
    while (i <= fileListe.length) {
        String newPath = folder.getName();
        if (!path.equalsIgnoreCase(""))
            newPath = path + "/" + newPath; 
...
voidaddFolderToZip(String path, String srcFolder, ZipOutputStream zip)
add Folder To Zip
File folder = new File(srcFolder);
for (String fileName : folder.list()) {
    if (path.equals("")) {
        addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip);
    } else {
        addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip);
voidaddFolderToZip(String path, String srcFolder, ZipOutputStream zip)
Adds the folder to zip.
final File folder = new File(srcFolder);
if (folder.list().length == 0) {
    addFileToZip(path, srcFolder, zip, true);
} else {
    for (String fileName : folder.list()) {
        if (path.equals("")) {
            addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, false);
        } else {
...
voidaddFolderToZip(String path, String srcFolder, ZipOutputStream zip, boolean addFolder)
add Folder To Zip
File folder = new File(srcFolder);
String listOfFiles[] = folder.list();
for (int i = 0; i < listOfFiles.length; i++) {
    String folderPath = null;
    if (path.length() < 1) {
        folderPath = folder.getName();
    } else {
        folderPath = path + File.separator + folder.getName();
...
voidaddFolderToZip(String path, String srcFolder, ZipOutputStream zip, boolean includeFullPath)
Zip the subdirectory and exclude already zipped files
File folder = new File(srcFolder);
for (String fileName : folder.list()) {
    if (path.equals("") && !fileName.endsWith(".zip")) {
        if (includeFullPath) {
            addFileToZip(folder.toString(), srcFolder + "/" + fileName, zip);
        } else {
            addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip);
    } else if (!fileName.endsWith(".zip")) {
        addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip);
voidaddFolderToZip(String pathInsideZip, final File folderToZip, final ZipOutputStream outZip)
add Folder To Zip
pathInsideZip = pathInsideZip.isEmpty() ? folderToZip.getName()
        : pathInsideZip + "/" + folderToZip.getName();
File[] files = folderToZip.listFiles();
if (files != null) {
    for (File file : files)
        addFileToZip(pathInsideZip, file, outZip);