在java中使用带密码保护的7zip进行压缩

问题描述 投票:0回答:1

我有一个加密文件,需要使用带有密码保护的 7zip 进行压缩。我在网上找不到任何有用的参考。我是这个 zip 文件的新手,我不知道这种方法是否正确。

我试过的代码

public int zipSingleFile(String compressedDo1FilePath, File encryptedFile) throws IOException {
    try{
    SevenZOutputFile out = new SevenZOutputFile(encryptedFile);
      SevenZArchiveEntry entry = out.createArchiveEntry(encryptedFile, compressedDo1FilePath);
      out.putArchiveEntry(entry);
      FileInputStream in = new FileInputStream(encryptedFile);
      byte[] b = new byte[1024];
      int count = 0;
      while ((count = in.read(b)) > 0) {
        out.write(b, 0, count);
      }
      out.closeArchiveEntry();
      return 0;
    } catch (IOException exception) {
      logger.info("exception occurred while zipping the file the file ={} ", exception);
      return 1;
    }
  }
java spring-boot compression 7zip
1个回答
0
投票

Apache Compress 只能读取加密的 7Zip 文件,您无法创建文件。

参考:https://commons.apache.org/proper/commons-compress/limitations.html

加密、固体压缩和标头压缩只是 读取档案时支持

© www.soinside.com 2019 - 2024. All rights reserved.