程序一直是运行好的,突然在另一台服务器上部署,发现不能解压文件, java.util.zip.ZipException:error in opening zip file
程序代码如下:
public static void unzip(String sourceZip, String outputPath) throws Exception {
if (sourceZip == null || outputPath == null) {
return;
}
ZipInputStream in = new ZipInputStream(new FileInputStream(sourceZip));
ZipEntry zipEntry = null;
while ((zipEntry = in.getNextEntry()) != null) {
File dir = new File(outputPath);
dir.mkdir();
File fil = new File(dir, zipEntry.getName());
FileOutputStream out = new FileOutputStream(fil);
int m = -1;
byte[] buffer = new byte[bufferSize];
while ((m = in.read(buffer, 0, 100)) != -1) {
out.write(buffer, 0, m);
}
out.close();
}
in.close();
}
Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:127)
at java.util.jar.JarFile.<init>(JarFile.java:135)
at java.util.jar.JarFile.<init>(JarFile.java:72)
at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:72)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:48)
at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:70)
因为是测试环境是可以跑起来,那说明是环境出了问题,后面经过排查,发现编译环境的JDK与生产环境的JDK版本不同。