Creating zip archive in Java

前端 未结 7 2123
一整个雨季
一整个雨季 2020-11-28 06:20

I have one file created by 7zip program. I used deflate method to compress it. Now I want to create the same archive (with the same MD5sum) in java

7条回答
  •  情书的邮戳
    2020-11-28 06:38

    ZipOutputStream has few methods to tune compression:

    public void setMethod(int method)

    Sets the default compression method for subsequent entries. This default will be used whenever the compression method is not specified for an individual ZIP file entry, and is initially set to DEFLATED.

    public void setLevel(int level)

    Sets the compression level for subsequent entries which are DEFLATED. The default setting is DEFAULT_COMPRESSION. level - the compression level (0-9)

    When you add after something like:

    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(target));
    zos.setMethod( ZipOutputStream.DEFLATED );
    zos.setLevel( 5 );
    ...
    

    does not it improve your compression?

提交回复
热议问题