Here you can find the source of addDirToArchive(ZipOutputStream zos, File srcFile)
Parameter | Description |
---|---|
zos | a parameter |
srcFile | a parameter |
public static void addDirToArchive(ZipOutputStream zos, File srcFile)
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { /**/*from w ww. j a v a 2s . c om*/ * Adds file / folder to zip output stream. Method works recursively. * @param zos * @param srcFile */ public static void addDirToArchive(ZipOutputStream zos, File srcFile) { File[] files = srcFile.listFiles(); for (int i = 0; i < files.length; i++) { // if the file is directory, use recursion if (files[i].isDirectory()) { addDirToArchive(zos, files[i]); continue; } try { // create byte buffer byte[] buffer = new byte[1024]; FileInputStream fis = new FileInputStream(files[i]); zos.putNextEntry(new ZipEntry(files[i].getName())); int length; while ((length = fis.read(buffer)) > 0) { zos.write(buffer, 0, length); } zos.closeEntry(); // close the InputStream fis.close(); } catch (IOException ioe) { System.out.println("IOException :" + ioe); } } } }