我正在尝试从服务器中提取 zip 文件(一个 zip 文件在服务器中。所以我试图通过 FTP 提取它)并且我正在使用此代码,
byte[] buf = new byte[1024];
ZipInputStream zinstream = new ZipInputStream(Home.ftpClient.retrieveFileStream("HO2BR.br.3162675983055490721.zync"));
ZipEntry zentry = zinstream.getNextEntry();
System.out.println("Name of current Zip Entry : " + zentry + "\n");
while (zentry != null) {
String entryName = zentry.getName();
System.out.println("Name of Zip Entry : " + entryName);
FileOutputStream outstream = new FileOutputStream(entryName);
int n;
while ((n = zinstream.read(buf, 0, 1024)) > -1) {
outstream.write(buf, 0, n);
}
System.out.println("Successfully Extracted File Name : " + entryName);
outstream.close();
zinstream.closeEntry();
zentry = zinstream.getNextEntry();
}
zinstream.close();
}
ZipInputStream(Home.ftpClient.retrieveFileStream("HO2BR.br.3162675983055490721.zync")); 为输入流分配FTPClient 的 retrieveFileStream
执行程序时出现此错误
java.util.zip.ZipException:无效距离太远在 java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
我该如何解决这个异常?