Hi, How can i create a zip file containing a csv file without the actual physical existance of the csv file. I have already developed the piece of code which creates a csv file and then this csv file is zipped and the original csv file is deleted. Well my task is to generate a csv file out of the dynamic data retrieved from the database. But i do not want any physical file to be created on the server. Niether the csv nor the zip file. The final downloadable file should be a zip file containing the csv file. As the user on my site clicks this button of download option the above task should be performed with no existance of file on the server. Thanks in advance - Nitin
Use a ZipOutputStream to create the zip file. You can write to this stream much like you previously wrote to a FileOutputStream to create the unzipped file. You can wrap the ZipOutputStream in other OutputStreams or Writers as you find necessary. You also need to add a few calls to putNextEntry() and closeEntry(), along with creating the appropriate ZipEntry info. If you're creating a zip file containing multiple entries, things get more complicated if you're using other high-level streams/Writers to create the individual entries. The problem is that if you use a particular high-level Writer just for one entry, and then close() it, the close() gets invoked on each nested stream, ultimately including the ZipOutputStream. This is a problem if you were still planning on writing additional entries. Even if you do not specifically close() the high-level streams, if they are garbage collected the close() may be invoked as part of finalization for that instance. (At least, I think this is true for some streams at least, though not all). You may find it useful to wrap the following stream around the ZipOutputStream (but inside any other high-level streams you use) to protect it from premature closure:
"I'm not back." - Bill Harding, Twister
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.