我有一个加密文件,需要使用带有密码保护的 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;
}
}
Apache Compress 只能读取加密的 7Zip 文件,您无法创建文件。
参考:https://commons.apache.org/proper/commons-compress/limitations.html
加密、固体压缩和标头压缩只是 读取档案时支持