我有以下java代码来创建一个zip文件。该文件在Linux上正常工作,但Windows XP的本地提取程序阻止它。建议的解决方法(转到文件属性并取消阻止)也不起作用。我已经阅读了关于网络上的类似问题以及关于此问题的类似帖子,但是这些解决方案都不适用于我。任何可能导致问题的想法。Windows XP阻止我的程序创建的zip文件
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ZipOutputStream zipFile = new ZipOutputStream(byteOut);
loop {
byte [] tempData = "some data".getBytes("UTF-8");
ZipEntry entry = new ZipEntry("blah.txt"); //no path here
entry.setSize(tempData.length); //read somewhere that this might solve the issue, didn't work
entry.setTime((new Date()).getTime()); //tried with and without this.. this is probably redundent since putNextEntry sets the time to current too.
zipFile.putNextEntry(entry);
zipFile.write(tempData);
zipFile.closeEntry();
}
zipFile.close();
附:
- 我的windows机器上没有windows defender。
- 我曾尝试设置zip条目的大小,但它仍然无效。
- 在zip条目中没有指定绝对路径,并且路径中没有斜杠。
谢谢!
编辑1:是的,我已经在Windows XP的其他机器上测试过,结果相同。我下载了7zip,但无法弄清楚如何检查压缩方法。如果有人能告诉我这样做的步骤,我可以将压缩方法添加到评论中。
编辑2:我使用windows本机提取向导,它说“Windows已阻止访问这些文件以帮助保护您的计算机”。在此消息的下面有一个链接,指出“Windows阻止标记为不可信的文件,为什么这些文件被阻止,我如何打开它们”。单击该链接可为您提供无法使用的解决方法(文件属性 - >解除阻止)。
奇怪...在另一台机器上测试过?另外,它使用什么压缩方法(7-zip可以告诉你)? – 2010-11-22 22:19:00