Gadget Corner, Huawei stock ROMs, Miracle Box, How To Install, Clone Firmware, Android Latest Version, HTC Firmware Flash File, and more information about gadgets for you

Java - Create Zip file in memory

Java - Create Zip file in memory - Welcome to the blog Gadget Corner we provide a lot of latest gadget information that must be very loss for you to miss, now we will discuss first about Java - Create Zip file in memory we have collected a lot of information to make this article complete for you, Ok please read::

You can also see our article on:


Java - Create Zip file in memory

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 about Java - Create Zip file in memory finished discussed

We think it is enough information about Java - Create Zip file in memory, hopefully the information we give can give benefit for you,

If you feel the information Java - Create Zip file in memory that we provide can provide benefits for others please share with link https://darellsfinancialcorner.blogspot.com/2008/04/java-create-zip-file-in-memory.html thank you for visiting our blog page and do not forget to visit other

Share on Facebook
Share on Twitter
Share on Google+
Tags :

Related : Java - Create Zip file in memory

0 komentar:

Posting Komentar