Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

merge content of two zip filesinside two different folders  RSS feed

 
fioana elegant
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can we merge content of two zip files,placed inside two different folders??
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me get this straight. You have ZIP files folder1\file1.zip and folder2\file2.zip. You want to create one ZIP file that contains the files in both source ZIP files. Well, that's not that hard.

1) Create a new ZipOutputStream for the output file: new ZipOutputStream(new FileOutputStream(file))
2) Open a ZipInputStream for the first file: new ZipInputStream(new FileInputStream(file))
3) Iterate over the ZipInputStream's entries (using getNextEntry())
3a) Put the entry into the ZipOutputStream.
3b) Copy the contents from the ZipInputStream to the ZipOutputStream. This works exactly as regular InputStream -> OutputStream copying.
3c) Close the entries of the ZipOutputStream and ZipInputStream.
4) Close the ZipInputStream.
5) Perform actions 2), 3) and 4) for the second file.
6) Close the ZipOutputStream.
 
fioana elegant
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply.i need csv file in the end instead of zip file
 
fioana elegant
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using this method do i need to mention 3rd file path for merged file???m confused how to pass different file path..please help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!