即使我设置为true,ZipFile.isSplitArchive也会返回false

时间:2015-03-18 10:55:36

标签: java junit zip4j

        // Initiate ZipFile object with the path/name of the zip file.
        ZipFile zipFile = new ZipFile("c:\\ZipTest\\CreateSplitZipFileFromFolder.zip");

        // Initiate Zip Parameters which define various properties such
        // as compression method, etc.
        ZipParameters parameters = new ZipParameters();

        // set compression method to store compression
        parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);

        // Set the compression level. This value has to be in between 0 to 9
        parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

        // Create a split file by setting splitArchive parameter to true
        // and specifying the splitLength. SplitLenth has to be greater than
        // 65536 bytes
        // Please note: If the zip file already exists, then this method throws an 
        // exception
        zipFile.createZipFileFromFolder("C:\\ZipTest", parameters, true, 10485760);

我从示例代码中复制了这个以使用zip4j,特别是名为CreateSplitZipFileFromFolder.java

的文件

问题是,即使我将createZipFileFromFolder的第三个参数设置为true,当我调用方法ZipFile.isSplitArchive()

时它仍会返回false 从grepcode

看来它只是将ZipModel对象设置为我设置的布尔标志,但是我得到了一个不同的值。任何想法为什么会这样?

1 个答案:

答案 0 :(得分:1)

生成的ZIP文件是否大于splitLength字节(在您的示例中为10485760)?来自createZipFile

的splitLength文档
  

如果必须拆分存档,则必须拆分

的字节长度

我假设只有在大于该大小的情况下才会创建拆分Zip文件。