Hi all,

I have a program which downloads a bunch of documents from a remote server and after bundles them up in a .zip file using ZipOutputStream.

The problem is that when I download the files, there could be more than one file with the same file name. So, when I try to put an entry with the same file name which is in ZipOutputStream, it will throw an exception "duplicate entry".

Is there a way, I can check for duplicate entry, before adding the zip entry to ZipOutputStream? so I can rename the file?

Please advise...


Thanks.

You could add the file names to a HashSet as you download them. The add() method will return false if the set already contains the item, at which point you could alter the filename, add it to the set and then write it to the zip stream.

You could add the file names to a HashSet as you download them. The add() method will return false if the set already contains the item, at which point you could alter the filename, add it to the set and then write it to the zip stream.

Thanks, I believe that should work.

Let me try, and will get back.

Thanks, it worked. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.