Created
August 14, 2013 22:51
-
-
Save bradical/6236499 to your computer and use it in GitHub Desktop.
A bad way to zip 800,000 files in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void zipFiles(File folderToZip, String zipFileToCreate) | |
{ | |
ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(zipFileToCreate)); | |
File[] files = folderToZip.listFiles(); | |
for (File file : files) | |
{ | |
String fileAbsolutePath = file.getAbsolutePath(); | |
String zipEntryName = fileAbsolutePath.substring(folderToZip.getAbsolutePath().length() + 1); | |
FileInputStream inputStream = new FileInputStream(file); | |
ZipEntry zipEntry = new ZipEntry(zipEntryName); | |
try | |
{ | |
zipStream.putNextEntry(zipEntry); | |
int temp; | |
while ((temp = bis.read()) != -1) | |
zipOutputStream.write(temp); | |
} | |
finally | |
{ | |
zipStream.closeEntry(); | |
inputStream.close(); | |
} | |
} | |
zipStream.finish(); | |
zipStream.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment