在 Windows 中(看起来像你在其中)我遇到了同样的问题,它似乎取决于文件相对于你的应用程序的位置。为了解决这个问题,我将输入文件复制到本地目录,对其进行压缩和加密,然后将输出文件移回输出文件的预期位置。
public static File aesEncrypt(String inFileFullPath, String outFileFullPath, String aesPassword) throws IOException{
File inFile = new File(inFileFullPath);
File localInput = new File(inFile.getName());
Files.copy(inFile, localInput);
File outFile = new File(outFileFullPath);
File localOutFile = new File(outFile.getName());
AESEncrypter aesEncrypter = new AESEncrypterBC();
aesEncrypter.init(aesPassword, 255);
AesZipFileEncrypter ze = new AesZipFileEncrypter(localOutFile, aesEncrypter);
ze.add(localInput, aesPassword);
ze.close();
Files.move(localOutFile, outFile);
localInput.delete();
return outFile;
}