/** * Pack all files in a directory to a zip file. * * @param sourceDirectory * @param targetFile * @throws IOException */ public static void archive(File sourceDirectory, File targetFile) throws IOException { if (!sourceDirectory.exists()) { throw new FileNotFoundException("File '" + sourceDirectory.getAbsolutePath() + "' is not exist!"); } if (sourceDirectory.isDirectory()) { String[] list = sourceDirectory.list(); if (list == null || list.length == 0) { throw new FileNotFoundException("Directory '" + sourceDirectory.getAbsolutePath() + "' is empty!"); } } OutputStream fos = new FileOutputStream(targetFile); try { archive(sourceDirectory, fos); } finally { fos.close(); } }
/** * Pack all files in a directory to a zip file. * * @param sourceDirectory * @param targetFile * @throws IOException */ public static void archive(File sourceDirectory, File targetFile) throws IOException { if (!sourceDirectory.exists()) { throw new FileNotFoundException("File '" + sourceDirectory.getAbsolutePath() + "' is not exist!"); } if (sourceDirectory.isDirectory()) { String[] list = sourceDirectory.list(); if (list == null || list.length == 0) { throw new FileNotFoundException("Directory '" + sourceDirectory.getAbsolutePath() + "' is empty!"); } } OutputStream fos = new FileOutputStream(targetFile); try { archive(sourceDirectory, fos); } finally { fos.close(); } }
ZipUtils.archive(originalZipFolder, modifiedZip); modifiedZipStream = new FileInputStream(modifiedZip);
ZipUtils.archive(originalZipFolder, modifiedZip); modifiedZipStream = new FileInputStream(modifiedZip);