TrueZip创建虚拟目录而不是存档

时间:2011-09-29 13:12:12

标签: java zip archiving java-6 truezip

我遇到以下代码的问题:

    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创建存档而不是(虚拟)目录?

2 个答案:

答案 0 :(得分:2)

它可能不起作用,因为运行时类路径上没有模块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);

答案 1 :(得分:0)

找到Apache的替代库Commons Compression。用它代替TrueZip。似乎也支持> 4gb文件。