【问题标题】:TrueZip creates virtual directory instead of archiveTrueZip 创建虚拟目录而不是存档
【发布时间】:2011-09-29 13:12:11
【问题描述】:

以下代码有问题:

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

【问题讨论】:

  • 你确定不是吗?一些操作系统将 zip 文件呈现为虚拟目录,至少是可选的。
  • 在切换到 TrueZip 之前,我使用了 Java 中的默认库 ZipOutputStream,并创建了条目。使用该库时,所有 ZIP 存档都显示为常规文件,而不是现在使用 TrueZip 时的目录。
  • 我也在尝试创建一个 zip 存档文件,但最终创建了一个目录。我正在 Windows (NTFS) 操作系统上试用它。你找到解决办法了吗?

标签: java zip archiving java-6 truezip


【解决方案1】:

它可能不起作用,因为模块 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);

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-06
      • 2010-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      相关资源
      最近更新 更多