• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

generate zip file containing a csv file

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic