New Java - Create Zip file in memory

New Java - Create Zip file in memory - lately we often hear a lot of new gadgets are released by famous brands that have a good spec, on the blog Anisa Gadget we will discuss about the review gagdet of all brands ranging from spek, price and how to use it, now we will discuss first about New Java - Create Zip file in memory please refer to the information we provide, because we have collected a lot of data to make this article to be complete for you:

Articles : New Java - Create Zip file in memory
full Link : New Java - Create Zip file in memory

You can also see our article on:


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



quite so many infromation New Java - Create Zip file in memory

hopefully the information we provide about New Java - Create Zip file in memory can give more benefits for you in determining the gadget that suits your needs.

you just read the article with the title New Java - Create Zip file in memory if intend to bookmark bookmark or share please use link https://anisapunyablog.blogspot.com/2008/04/new-java-create-zip-file-in-memory.html to get more information about technology please visit other pages on this blog, thank you.

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

Related : New Java - Create Zip file in memory

0 komentar:

Posting Komentar