简体   繁体   中英

How to archive (using Zip) into multiple output files

In Android I want to pack some files into Zip archive (using java.util.zip ). But I have a limit for output file size - so is there a possibility to pack them into multiple, fixed-size files?

What if you do it like this:

Let's say, that you know (aproximately) the compress ratio of your files... You take first few files that doesn't exceed for example 2MB. If compress ratio is 50% you'll get 1MB file at the end. You repeat the process untill you zip all the files...

Regarding one big text file I would suggest this. Read the file and write it into two/three/four seperate files. You can do this with FileInputStream and FileOutputStream ... ZIP each of parts.. After unziping, glue them together again with help of File(Input/Output)Stream .

We had a need to do something similar recently (not on Android but the principle is the same). We came up with a MultiFileOutputStream which writes to a series of fixed-size "chunks" and a corresponding input stream that reassembles the chunks into one stream again. We layer a commons-compress TAR stream on top of the multi-file stream but you could equally well use a zip stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM