you're looking for: New Java - Create Zip file in memory By Gamzeozgesaroglu
complete information: New Java - Create Zip file in memory By Gamzeozgesaroglu
Artikel java, Artikel sample code, Artikel tips and tricks,
New Java - Create Zip file in memory By Gamzeozgesaroglu
I find myself writing and rewriting this piece of code whenever I want to zip a set of files (in memory) and return the zipped file back as an object in memory. I often use this when the user requests a download of multiple reports and the deployment environment doesn't allow for disk access.I thought I'd post it here so that I could copy-paste it the next time I need it :) If you've stumbled upon this page, you're free to use the code below too!
private static byte[] createZip(Map files) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zipfile = new ZipOutputStream(bos);
Iterator i = files.keySet().iterator();
String fileName = null;
ZipEntry zipentry = null;
while (i.hasNext()) {
fileName = (String) i.next();
zipentry = new ZipEntry(fileName);
zipfile.putNextEntry(zipentry);
zipfile.write((byte[]) files.get(fileName));
}
zipfile.close();
return bos.toByteArray();
}
Articles New Java - Create Zip file in memory By Gamzeozgesaroglu we have presented
That's all the information about the New Java - Create Zip file in memory By Gamzeozgesaroglu, hopefully can provide benefits to all of you in finding information latest gadgets, how to care for gadgets, tips and tricks mobile phone.
Thank you for reading the article New Java - Create Zip file in memory By Gamzeozgesaroglu and its url of this article is https://gamzeozgesaroglu.blogspot.com/2008/04/new-java-create-zip-file-in-memory-by.html o you to bookmark and you can go back if you need :), I hope the article this can be useful for you all.
0 Response to "New Java - Create Zip file in memory By Gamzeozgesaroglu"
Post a Comment