我在使用以下代码时遇到问题:
TFile src = new TFile(this.getMellomStasjon());
TFile dst = new TFile(this.getZipFolder()+""+zipFile+".zip");
if(dst.isDirectory())
dst = new TFile(dst, src.getName());
TFile.cp_rp(src, dst, null);
TFile file = newNonArchiveFile(dst);
if(dst.isArchive())
TFile.umount(dst);
我的目标是使用 TrueZip 将包含文件的目录放入 ZIP 存档中。问题是代码在本地工作,但在生产计算机上却不行。在本地我得到一个 ZIP 文件,但在生产中我得到一个文件夹,其中包含我试图放入存档(虚拟目录)的文件。我必须使用 TrueZip,因为我要归档超过 4GB 的内容。
有什么方法可以强制 TrueZip 创建存档而不是(虚拟)目录?
最佳答案
它可能没有工作,因为模块 TrueZIP Driver ZIP 的 JAR 工件不存在于运行时类路径中。
为了确保它是,您可以通过设置自定义 TArchiveDetector 使 ZipDriver 成为编译时依赖项。这是一个例子:http://truezip.java.net/usecases/aff.html
您在此处显示的代码有问题。您应该将其修复为:
// Call this once at application startup to make the ZipDriver a compile time
// dependency.
TFile.setDefaultArchiveDetector(
new TArchiveDetector(
"zip",
new ZipDriver(IOPoolLocator.SINGLETON)));
// Here's the work.
TFile src = new TFile(this.getMellomStasjon());
TFile dst = new TFile(this.getZipFolder(), zipFile + ".zip");
TFile.cp_rp(src, dst, TArchiveDetector.NULL);
TFile.umount(dst);
关于java - TrueZip 创建虚拟目录而不是存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7597836/