How to estimate zip file size in java before creating it

后端 未结 7 418
时光取名叫无心
时光取名叫无心 2021-01-08 00:27

I am having a requirement wherein i have to create a zip file from a list of available files. The files are of different types like txt,pdf,xml etc.I am using java util clas

7条回答
  •  一生所求
    2021-01-08 01:03

    I did this once on a project with known input types. We knew that general speaking our data compressed around 5:1 (it was all text.) So, I'd check the file size and divide by 5...

    In this case, the purpose for doing so was to check that files would likely be below a certain size. We only needed a rough estimate.

    All that said, I have noticed zip applications like 7zip will create a zip file of a certain size (like a CD) and then split the zip off to a new file once it reaches the limit. You could look at that source code. I have actually used the command line version of that app in code before. They have a library you can use as well. Not sure how well that will integrate with Java though.

    For what it is worth, I've also used a library called SharpZipLib. It was very good. I wonder if there is a Java port to it.

提交回复
热议问题