我使用以下简单的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();
压缩文件已成功创建。但是,当我尝试使用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解压文件时没有显示任何错误。
我做错了什么?有人遇到过这个问题吗? 谢谢!