How to estimate zip file size in java before creating it

后端 未结 7 420
时光取名叫无心
时光取名叫无心 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:06

    Maybe you could add a file each time, until you reach the 5MB limit, and then discard the last file. Like @Gopi, I don't think there is any way to estimate it without actually compressing the file.

    Of course, file size will not increase (or maybe a little, because of the zip header?), so at least you have a "worst case" estimation.

提交回复
热议问题