Here you can find the source of addDirToArchive(ZipOutputStream zop, File srcFile)
Parameter | Description |
---|---|
zop | ZipOutputStream from zipRollbackPackage. |
srcFile | The files in this directory to be zipped. |
Parameter | Description |
---|---|
Exception | an exception |
private static void addDirToArchive(ZipOutputStream zop, File srcFile) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { /**//from w w w .j av a 2 s . co m * Helper method that aids zipRollbackPackage in recursively creating a zip file from a directory's contents. * @param zop ZipOutputStream from zipRollbackPackage. * @param srcFile The files in this directory to be zipped. * @throws Exception */ private static void addDirToArchive(ZipOutputStream zop, File srcFile) throws Exception { File[] files = srcFile.listFiles(); for (File file : files) { if (file.isDirectory()) { addDirToArchive(zop, file); continue; } byte[] buffer = new byte[1024]; FileInputStream fis = new FileInputStream(file); zop.putNextEntry(new ZipEntry(file.getName())); int length; while ((length = fis.read(buffer)) > 0) { zop.write(buffer, 0, length); } zop.closeEntry(); fis.close(); } } }