Java - Create Zip file in memory

Java - Create Zip file in memory - welcome to our blog that presents the full content How Gadget, the discussion this time we're discussing that you find that Java - Create Zip file in memory, we have provided complete information with images that are easy to understand, the explanation is simple but complete, therefore please read until the end :)

This is about : Java - Create Zip file in memory
And this article : Java - Create Zip file in memory

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();
}



Information Java - Create Zip file in memory has been completed we present

A few of our information about the Java - Create Zip file in memory, we hope you benefit from this article

You have just read the article Java - Create Zip file in memory and many articles about gadget in our blog this, please read it. and url link of this article is https://howtomonetizeeverything.blogspot.com/2008/04/java-create-zip-file-in-memory.html Hopefully discussion articles on provide more knowledge about the world of tech gadgets.

Tag :

0 Response to "Java - Create Zip file in memory"

Post a Comment