加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

找不到Java 9 Zip End Header异常

发布时间:2020-12-15 00:44:20 所属栏目:Java 来源:网络整理
导读:我试图使用 java – SRTM files从这个URL批量下载zip文件,它需要用户名/密码下载,我使用以下java代码,它给了我以下异常 java.util.zip.ZipException: zip END header not foundat java.util.zip.ZipFile$Source.zerror(java.base@9-internal/ZipFile.java:12
我试图使用 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,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-04-14与撰写本文时的2017年7月),您应该升级到最新的Java 9 EA版本或坚持使用Java 8直到公开发布Java 9.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读