java - 即使我设置为 true,ZipFile.isSplitArchive 仍返回 false

标签 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 对象设置为我设置的 boolean 标志,但我得到了不同的值。有什么想法吗?

最佳答案

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

if archive has to be split, then length in bytes at which it has to be split

我假设只有当分割的 Zip 文件大于该大小时才会创建它。

关于java - 即使我设置为 true,ZipFile.isSplitArchive 仍返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29120135/

相关文章:

java - 如何将我的 Java 应用程序连接到通过 docker 运行的 Cassandra?

java - 如何验证是否在被测系统上调用了方法(不是模拟)

java - PowerMock 和 Mockito 的静态模拟不起作用

java - 如何在 JUnit 中构建自动回复 JMS 监听器(在 OpenEJB 中)

Zip4J 和 Zip Slip 漏洞

java - 未找到 Zip header ,可能不是 zip 文件 - Zip4j、java

java - Wiremock 对于 stub url 返回 404

java - 从 Mega.nz 加载文件以在 java 项目中使用

java - JPA:双向 m:n 关系中的数据访问

java - 将 Zip 内容读入字符串时出现 "ZipException - unexpected end of file when reading short buff"