how to create java zip archives with a max file size limit
java, zip
Solution
zip4j is a great library that can create multi-part zip files.
net.lingala.zip4j.core.ZipFile zipFile = new ZipFile("out.zip");
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipFile.createZipFileFromFolder("path/to/source/dir", parameters, true, maximum size);
You can find more examples on their web-site.
Problem
I need to write an algorithm in java (for an android app) to read a folder containing more folders and each of those containing images and audio files so the structure is this: `mainDir/categorySubfolder/myFile1.jpg` My problem is that I need to limit the size of the archive to 16mb and at runtime, create as many archives as needed to contain all my files from my main `mainDir` folder. I tried several examples from the net and I read the java documentation but I can't manage to understand and put it all together the way I need it. Has someone done this before or has a link or an example for me? I resolved the reading of the files with a recursive method but I can't write the logic for the zip creation. I'm open for suggestions or better a working example.