日期:2014-05-18  浏览次数:20721 次

用java程序打的zip包和直接右键用WinRAR打的zip有区别,怎么办啊
我现在调别人的接口,需要传一个zip包的路径。这个zip包有一个xml文件。我要做的是把xml文件压缩成zip包
我生成xml文件后,右键用WinRAR打的zip包。在调他们的接口,可以成功解析的我的xml文件。

然而我用java程序去打包,这个时候生产的zip包。去调他们的接口,居然不认识我的zip包,解析不了我的xml文件。
我把zip解压出来看了,有我的xml,而且xml的内容没有乱码,没有错,很完整。

为什么会有这样的情况。我快疯了。难道是打包的代码不对?我的代码生产的zip包,解压出来就是那个xml文件。

我的错是哪里啊? 谁知道一下啊?拜托了!!

能够把发个把xml打成zip包的代码给我更感谢!!

------解决方案--------------------
如果你生成的zip文件可以用WinRar打开并解压成功,那么错误就是他们而不是你的

是否你们约定的ZipEntry名字不一样(区分大小写)

错误的异常是什么?
------解决方案--------------------
我感觉是一样的  没什么区别!
------解决方案--------------------
public class Compress {

public static void main(String[] args) throws IOException {
File file = new File("D:/build.xml");
ZipOutputStream zipOutputStream = new ZipOutputStream(
new FileOutputStream(new File("D:/zip/xxx.zip")));
BufferedInputStream bufferdInputStream = new BufferedInputStream(
new FileInputStream(file));
byte[] buffer = new byte[1024];
zipOutputStream.putNextEntry(new ZipEntry(file.getName()));
int length = 0;
while (true) {
length = bufferdInputStream.read(buffer);
if (length < 0) {
break;
}
zipOutputStream.write(buffer, 0, length);
}
zipOutputStream.flush();
bufferdInputStream.close();
zipOutputStream.closeEntry();
zipOutputStream.close();
}

}
------解决方案--------------------
lz,不要考虑太多了,没什么区别得