【问题标题】:Java 9 Zip End Header Not Found ExceptionJava 9 Zip End Header Not Found 异常
【发布时间】:2017-07-04 07:19:30
【问题描述】:

为 Google 员工编辑:事实证明这是由于使用了 Java 9 的过时 beta 版本造成的。

我正在尝试使用 java - SRTM files 从该 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);
    }

有人可以帮助我为什么会失败吗?

【问题讨论】:

  • @AdamMichalik - 感谢您的及时回复。那么在 Ubuntu 16.04 上我该如何升级呢? :) 再安装一次?
  • @AdamMichalik - 更好的选择是安装 jdk-8 ?
  • 根据您可以花在上面的时间,您可以同时尝试。最简单的方法是使用 PPA 中的 Java 包:launchpad.net/~webupd8team/+archive/ubuntu/java。在此处阅读说明:webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html。安装后使用java -v 确保实际使用了正确的版本。
  • @AdamMichalik - 谢谢我使用了 java 8,它现在可以完美运行了。
  • 这发生在我身上。或者,我通过 IntelliJ 添加了 JAR 作为 Maven repo jar,这解决了问题。

标签: java http download ubuntu-16.04 java-9


【解决方案1】:

Java 9 的一些(已经关闭)错误提到了这个异常(例如,JDK-8170276JDK-8172872)。由于 Java 9 仍处于测试阶段,并且您使用的是一年多前的版本(2016-04-14 与撰写本文时的 2017 年 7 月),您应该升级到最新的 Java 9 EA 版本或坚持使用 Java 8直到 Java 9 公开发布。

【讨论】:

    猜你喜欢
    • 2022-06-27
    • 1970-01-01
    • 2020-07-11
    • 2021-02-17
    • 2018-12-09
    • 1970-01-01
    • 2016-01-22
    • 2018-08-22
    • 2017-03-25
    相关资源
    最近更新 更多