1

Hello I need to split a zip file into multiple samaller files, ex. file.zip is splitted into files with fixed size less than 640MB and format nameOfZip.zip.001

I am currently looking for some kind of a java library that would be able to do this. If there is no such, advice would be very helpful too.

  • Possibly related: [How to break a file into pieces using Java?](https://stackoverflow.com/q/10864317) – Pshemo Mar 27 '22 at 16:17
  • I will give it a shot, thank you – Alexander Mladzhov Mar 27 '22 at 17:10
  • if you want post it as answer and I will mark it as accepted – Alexander Mladzhov Mar 28 '22 at 07:44
  • There is no need to repeat same answer in many places. We have *duplicates* system for that so I marked your question as duplicate of question I lined earlier. Don't think having question marked as duplicate is something bad. Duplicates are meant to be road signs leading to correct answer, so they are useful. – Pshemo Mar 28 '22 at 10:23

1 Answers1

3

Zip, the format, can do this. You can then unzip the batch of files with plain jane unzip on the command line (or with tools like p7zip and such, or you can just doubleclick the zip on a mac, etcetera).

Unfortunately, the baked in zip support in java can't make split zips. But, Lingala / Zip4j can do it.

Add that library to your list of dependencies and use its API (forget about java.io.ZipOutputStream, or the Zip FileSystem - anything that starts with java.* can't do this.

Alternatively it is trivial to write code in java to just split any file. You'd need to write java code as well to put them back together, or you need to know a few things about your OS to do this (e.g. cat a.bin b.bin >c.bin on posix OSes will put a.bin and b.bin back together). This isn't difficult at all, just your basic file and outputstream support can trivially put it together in less than a page's worth of java code. No libraries exist, and probably never will - that is a very simple task that isn't common enough to make a library for.

So, if that's what you're looking for, go ahead and write it yourself. All you need is the javadoc of java.nio.file.Paths and java.nio.file.Files.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72