/* * Copyright 2010 Srikanth Reddy Lingala * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.lingala.zip4j.examples.zip; import net.lingala.zip4j.core.ZipFile; import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.model.ZipParameters; import net.lingala.zip4j.util.Zip4jConstants; /** * Demonstrated adding a folder to zip file * * @author Srikanth Reddy Lingala */ public class AddFolder { public AddFolder() { try { // Initiate ZipFile object with the path/name of the zip file. ZipFile zipFile = new ZipFile("c:\\ZipTest\\AddFolder.zip"); // Folder to add String folderToAdd = "c:\\FolderToAdd"; // Initiate Zip Parameters which define various properties such // as compression method, etc. ZipParameters parameters = new ZipParameters(); // set compression method to store compression parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // Set the compression level parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); // Add folder to the zip file zipFile.addFolder(folderToAdd, parameters); } catch (ZipException e) { e.printStackTrace(); } } public static void main(String[] args) { new AddFolder(); } }