使用TrueZip创建受密码保护的ZIP文件

时间:2013-05-08 17:22:15

标签: java truezip

有没有人知道使用TrueZip创建受密码保护的ZIP文件的好例子?

我按照TrueZip Example给出的示例,但提取密码保护的zip文件时,不接受我通过java代码设置的正确密码。

1 个答案:

答案 0 :(得分:3)

我找到了解决方案

try {
        final TConfig config = TConfig.get();

        // Request encryption in archive files.
        config.setOutputPreferences(config.getOutputPreferences()
                .or(BitField.of(FsOutputOption.ENCRYPT)));

        // Configure archive detector with custom key management for ZIP files.
        config.setArchiveDetector(newArchiveDetector1("zip", "password"));

        // Setup file paths.
        TFile src = new TFile("file1");
        TFile dst = new TFile("file2");
        if (dst.isArchive() || dst.isDirectory())
            dst = new TFile(dst, src.getName());

        // Recursive copy.
        src.cp_rp(dst);
    } finally {
        // Commit changes.
        TVFS.umount();
    }
相关问题