【问题标题】:Adding an entry to nested zip File using commons.apache.compress使用 commons.apache.compress 向嵌套 zip 文件添加条目
【发布时间】:2013-02-26 12:08:03
【问题描述】:

我的 Zip 文件结构是这样的:

t1.zip --> t2.zip --> sample.txt

我想替换 sample.txt。如果它是一个级别,我能够做到。请帮助我处理多层嵌套的 zip 文件。

我的示例代码

ZipFile zipFile = new ZipFile(new File("t1.zip");
ZipArchiveEntry ze = zipFile.getEntry("t2.zip"); // So It works fine

我试过了

ZipArchiveEntry ze = zipFile.getEntry("t2.zip/sample.txt"); // returns null

我的意图是遵循 apache 文档页面中的示例

ZipArchiveEntry entry = new ZipArchiveEntry(new File("sample.txt")); // Should I t2.zip/sample.txt ?
entry.setSize(size);
zipOutput.putArchiveEntry(entry);
zipOutput.write(contentOfEntry);
zipOutput.closeArchiveEntry();

但我不清楚,如何将归档条目 2 级放在里面?

【问题讨论】:

  • 我添加了我尝试过的示例代码

标签: java apache-commons-compress


【解决方案1】:

你必须使用

new ZipArchiveEntry(new File("sample.txt"), "sample.txt");

将文件设置到根文件夹和

new ZipArchiveEntry(new File("sample.txt"), "new folder/sample.txt");

设置到一个名为“新文件夹”的新文件夹中。

【讨论】:

    猜你喜欢
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多