[英]Java 9 Zip End Header Not Found Exception
為 Google 員工編輯:結果證明這是由使用過時的 Java 9 測試版引起的。
我正在嘗試使用 java - SRTM文件從這個 URL 批量下載 zip 文件,它需要用戶名/密碼才能下載,我正在使用以下 java 代碼,它給了我以下異常
java.util.zip.ZipException: zip END header not found
at java.util.zip.ZipFile$Source.zerror(java.base@9-internal/ZipFile.java:1210)
at java.util.zip.ZipFile$Source.findEND(java.base@9-internal/ZipFile.java:1119)
at java.util.zip.ZipFile$Source.initCEN(java.base@9-internal/ZipFile.java:1126)
at java.util.zip.ZipFile$Source.<init>(java.base@9-internal/ZipFile.java:963)
at java.util.zip.ZipFile$Source.get(java.base@9-internal/ZipFile.java:933)
at java.util.zip.ZipFile.<init>(java.base@9-internal/ZipFile.java:213)
at java.util.zip.ZipFile.<init>(java.base@9-internal/ZipFile.java:145)
at java.util.zip.ZipFile.<init>(java.base@9-internal/ZipFile.java:159)
at toposwapper.rules.ZipFileDownloadAction.execute(ZipFileDownloadAction.java:29)
這是我的java版本
java openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src)
OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode)
這是我用來下載的代碼 -
URL url1 = null;
URLConnection conn = null;
InputStream inputs = null;
FileOutputStream out = null;
try
{
url1 = new URL(url);
conn = url1.openConnection();
conn.setDoInput(true);
conn.setDoOutput(false);
conn.setRequestProperty("file-name", output.getName());
conn.setRequestProperty("content-type","application/zip");
String userpass = this.username + ":" + this.password;
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
conn.setRequestProperty("Authorization",basicAuth);
}
catch (MalformedURLException ex) {
Logger.getLogger(SrtmDownloadManager.class.getName()).log(Level.SEVERE, "", ex);
throw new TopoSwapperException(ex.getMessage());
}
catch (IOException ioe)
{
Logger.getLogger(SrtmDownloadManager.class.getName()).log(Level.SEVERE, "", ioe);
throw new TopoSwapperException(ioe.getMessage());
}
try
{
inputs = conn.getInputStream();
out = new FileOutputStream(output);
byte[] b = new byte[1024];
int count;
while ((count = inputs.read(b)) > -1)
{
out.write(b,0,count);
}
out.flush();
inputs.close();
out.close();
}
catch (FileNotFoundException ex)
{
throw new TopoSwapperException(ex.getMessage());
}
catch (IOException ex)
{
Logger.getLogger(SrtmDownloadManager.class.getName()).log(Level.SEVERE, "", ex);
throw new TopoSwapperException(ex.getMessage());
}
finally
{
close(inputs);
close(out);
}
有人可以幫助我為什么會失敗嗎?
Java 9 有一些(已經關閉的)錯誤提到了這個異常(例如JDK-8170276 、 JDK-8172872 )。 由於 Java 9 仍處於測試階段,並且您使用的是一年多以前的版本(2016 年 4 月 14 日與撰寫本文時的 2017 年 7 月),您應該升級到最新的 Java 9 EA 版本或堅持使用 Java 8直到 Java 9 公開發布。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.