File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes how to split a Zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "how to split a Zip file" Watch "how to split a Zip file" New topic

how to split a Zip file

Ranch Hand

Joined: Jan 23, 2008
Posts: 31
I have ziped the files into a file, If file is bigger, for example, its size is bigger than 10MB, I want to split into 5 files which is not bigger than 2MB . How do i need to do this?
Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

I am not aware of any public API that will help you do that.
(Although if you do not want to do it programatically, there are utilities like WinSplitter that will do it)

I have not tried it but, every ZipEntry while using ZippedInput/OutputStream has a compressed size. You may get a rough estimate of the size of the zipped file while creating it. If you need 2MB of zipped files, then you can stop writing to a file after the cumulative size of entries become 1.9MB, taking .1MB for Manifest file and other zip file specific elements.

So, in a nutshell, you can write a wrapper over the ZippedInputStream as follows:

The above program is just a hint of the approach and not a final solution by any means.
[ June 10, 2008: Message edited by: Nitesh Kant ]

apigee, a better way to API!
I agree. Here's the link:
subject: how to split a Zip file
It's not a secret anymore!