|
|
|
@ -16,9 +16,12 @@ public class ZipUtils {
|
|
|
|
|
public static void ZipFolder(File srcDirectory, File zipFile, FilenameFilter filter) {
|
|
|
|
|
ZipOutputStream outZip = null;
|
|
|
|
|
FileInputStream inputStream = null;
|
|
|
|
|
FileOutputStream fileOutputStream = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
outZip = new ZipOutputStream(new FileOutputStream(zipFile));
|
|
|
|
|
fileOutputStream = new FileOutputStream(zipFile);
|
|
|
|
|
outZip = new ZipOutputStream(fileOutputStream);
|
|
|
|
|
|
|
|
|
|
int len;
|
|
|
|
|
byte[] buffer = new byte[1024 * 256];
|
|
|
|
|
ZipEntry zipEntry = null;
|
|
|
|
@ -48,6 +51,7 @@ public class ZipUtils {
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
FilesUtils.closeFriendly(fileOutputStream);
|
|
|
|
|
FilesUtils.closeFriendly(outZip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -55,9 +59,11 @@ public class ZipUtils {
|
|
|
|
|
public static void ZipFolders(Map<String, File> srcDirectories, File zipFile, FilenameFilter filter) {
|
|
|
|
|
ZipOutputStream outZip = null;
|
|
|
|
|
FileInputStream inputStream = null;
|
|
|
|
|
FileOutputStream fileOutputStream = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
outZip = new ZipOutputStream(new FileOutputStream(zipFile));
|
|
|
|
|
fileOutputStream = new FileOutputStream(zipFile);
|
|
|
|
|
outZip = new ZipOutputStream(fileOutputStream);
|
|
|
|
|
int len;
|
|
|
|
|
byte[] buffer = new byte[1024 * 256];
|
|
|
|
|
ZipEntry zipEntry = null;
|
|
|
|
@ -91,6 +97,7 @@ public class ZipUtils {
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
FilesUtils.closeFriendly(fileOutputStream);
|
|
|
|
|
FilesUtils.closeFriendly(outZip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -99,10 +106,10 @@ public class ZipUtils {
|
|
|
|
|
|
|
|
|
|
ZipOutputStream outZip = null;
|
|
|
|
|
FileInputStream inputStream = null;
|
|
|
|
|
|
|
|
|
|
FileOutputStream fileOutputStream = null;
|
|
|
|
|
try {
|
|
|
|
|
outZip = new ZipOutputStream(new FileOutputStream(zipFile));
|
|
|
|
|
// ZipFiles(srcFile.getParent() + File.separator, srcFile.getName(), outZip);
|
|
|
|
|
fileOutputStream = new FileOutputStream(zipFile);
|
|
|
|
|
outZip = new ZipOutputStream(fileOutputStream);
|
|
|
|
|
int len = 0;
|
|
|
|
|
byte[] buffer = new byte[1024 * 256];
|
|
|
|
|
|
|
|
|
@ -111,16 +118,15 @@ public class ZipUtils {
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
ZipEntry zipEntry = new ZipEntry(path);
|
|
|
|
|
ZipEntry zipEntry = new ZipEntry(srcFiles.size() > 1 ? path.substring(1) : file.getName());
|
|
|
|
|
inputStream = new FileInputStream(file);
|
|
|
|
|
outZip.putNextEntry(zipEntry);
|
|
|
|
|
|
|
|
|
|
outZip.putNextEntry(zipEntry);
|
|
|
|
|
while ((len = inputStream.read(buffer)) != -1) {
|
|
|
|
|
outZip.write(buffer, 0, len);
|
|
|
|
|
}
|
|
|
|
|
FilesUtils.closeFriendly(inputStream);
|
|
|
|
|
|
|
|
|
|
outZip.closeEntry();
|
|
|
|
|
FilesUtils.closeFriendly(inputStream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -134,6 +140,7 @@ public class ZipUtils {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FilesUtils.closeFriendly(fileOutputStream);
|
|
|
|
|
FilesUtils.closeFriendly(outZip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|