/** * Create a structured zip archive recursively. * The string must be OS specific String to represent path. * */ public static void zipDir(final String dir2zip, final ZipOutputStream zos, final String root) throws IOException { final File zipDir = new File(dir2zip); final byte[] readBuffer = new byte[BUFFER_SIZE]; for (final String pathName : zipDir.list()) { final File file = new File(zipDir, pathName); final String path = file.getPath(); if (file.isDirectory()) { zipDir(path, zos, root); continue; } try { final ZipEntry anEntry = new ZipEntry(path.substring(root.length() + 1, path.length()).replace(String.valueOf(File.separatorChar), "/")); zos.putNextEntry(anEntry); copyFileToZip(zos, readBuffer, file); zos.flush(); } finally { zos.closeEntry(); } } }
/** * Create a structured zip archive recursively. * The string must be OS specific String to represent path. * */ public static void zipDir(final String dir2zip, final ZipOutputStream zos, final String root) throws IOException { final File zipDir = new File(dir2zip); final byte[] readBuffer = new byte[BUFFER_SIZE]; for (final String pathName : zipDir.list()) { final File file = new File(zipDir, pathName); final String path = file.getPath(); if (file.isDirectory()) { zipDir(path, zos, root); continue; } try { final ZipEntry anEntry = new ZipEntry(path.substring(root.length() + 1, path.length()).replace(String.valueOf(File.separatorChar), "/")); zos.putNextEntry(anEntry); copyFileToZip(zos, readBuffer, file); zos.flush(); } finally { zos.closeEntry(); } } }