private static void addDirectoryToZip(File dir, String dirName, ZipOutputStream zos) throws IOException { final ZipEntry dirEntry = new ZipEntry(dirName + "/"); zos.putNextEntry(dirEntry); zos.closeEntry(); File[] children = dir.listFiles(); if (children != null) { for (File file : children) { if (file.isDirectory()) { addDirectoryToZip(file, dirName + "/" + file.getName(), zos); } else { addFileToZip(file, dirName, zos); } } } }
public static void zip(File sourceDir, File zipFile) { try (final FileOutputStream os = new FileOutputStream(zipFile); final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(os)) ) { for (final File file : sourceDir.listFiles()) { if (file.isDirectory()) { addDirectoryToZip(file, file.getName(), zos); } else { addFileToZip(file, null, zos); } } } catch (IOException e) { throw new RuntimeException("Failed creating patch file " + zipFile, e); // Only used for generation and tests } }
private static void addDirectoryToZip(File dir, String dirName, ZipOutputStream zos) throws IOException { final ZipEntry dirEntry = new ZipEntry(dirName + "/"); zos.putNextEntry(dirEntry); zos.closeEntry(); File[] children = dir.listFiles(); if (children != null) { for (File file : children) { if (file.isDirectory()) { addDirectoryToZip(file, dirName + "/" + file.getName(), zos); } else { addFileToZip(file, dirName, zos); } } } }
public static void zip(File sourceDir, File zipFile) { try (final FileOutputStream os = new FileOutputStream(zipFile); final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(os)) ) { for (final File file : sourceDir.listFiles()) { if (file.isDirectory()) { addDirectoryToZip(file, file.getName(), zos); } else { addFileToZip(file, null, zos); } } } catch (IOException e) { throw new RuntimeException("Failed creating patch file " + zipFile, e); // Only used for generation and tests } }