【问题标题】:File zipped by java.util.zip can't be decompressed by standard zip utility由 java.util.zip 压缩的文件不能被标准 zip 实用程序解压缩
【发布时间】:2011-11-18 18:38:28
【问题描述】:

我设法使用这段简单的代码在 java 中创建了 zip 文件:

BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream(zipFile);

ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
out.setMethod(ZipOutputStream.DEFLATED);
out.setLevel(5);

byte data[] = new byte[BUFFER];
FileInputStream fi = new FileInputStream(file);
origin = new BufferedInputStream(fi, BUFFER);

ZipEntry entry = new ZipEntry(file.getName());
out.putNextEntry(entry);

int count;
while ((count = origin.read(data, 0, BUFFER)) != -1) {
    out.write(data, 0, count);
}

out.closeEntry();
origin.close();
out.close();

zip 文件创建成功。但是,当我尝试使用 WinZip 或其他一些工具解压缩它时,我得到一个错误:

Central and local directory mismatch for file "my_file" (general 
purpose flags - local:808 hex  central: 8 hex). 
Severe Error:  Local and central GPFlags values don't match.

真正奇怪的是,当我解压文件时,WinRAR 和内部 Win7 zip 不会显示任何错误。

我做错了什么?有人有这个问题吗? 非常感谢!

【问题讨论】:

标签: java android zip


【解决方案1】:

一定是 out.close 不见了。

【讨论】:

    【解决方案2】:

    我想你忘了关闭 zipentry。

    out.closeEntry();
    origin.close();
    out.close();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多