我有以下java代码来创建一个zip文件。该文件在Linux上工作正常,但Windows XP的本机提取器阻止它。建议的解决方法(转到文件属性和取消阻止)也不起作用。我已经阅读了关于Web上的类似问题以及关于此的stackoverflow上的类似帖子,但这些解决方案都不适用于我。关于可能导致问题的任何想法。
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();
P.S。
谢谢!
编辑1 :是的,我已在其他使用Windows XP的计算机上测试过相同的结果。我下载了7zip,但无法弄清楚如何检查压缩方法。如果有人可以告诉我这样做的步骤,我可以在评论中添加压缩方法。
编辑2 :我使用Windows原生提取向导,其中显示“Windows已阻止访问这些文件以帮助保护您的计算机”。在此消息下方有一个链接,显示“Windows阻止标记为不受信任的文件。为什么这些文件被阻止,我如何打开它们”。单击该链接可为您提供无效的解决方法(文件属性 - >取消阻止)。
答案 0 :(得分:0)
刚刚发现问题,我的输入文件名中有一个时间戳,上面有一个:而且窗户吓坏了。
ZipEntry entry = new ZipEntry(“blah.txt”); < - 时间戳在这里,没想到这很重要所以没有在这里复制真实姓名。