2017-07-04 41 views
5

Tôi đang cố gắng tải xuống hàng loạt tệp zip từ URL này bằng java - SRTM files và yêu cầu tên người dùng/mật khẩu để tải xuống và tôi đang sử dụng mã java sau và nó mang lại cho tôi ngoại lệ sauJava 9 Zip End Header Không tìm thấy Ngoại lệ

java.util.zip.ZipException: zip END header not found 
at java.util.zip.ZipFile$Source.zerror([email protected]/ZipFile.java:1210) 
at java.util.zip.ZipFile$Source.findEND([email protected]/ZipFile.java:1119) 
at java.util.zip.ZipFile$Source.initCEN([email protected]/ZipFile.java:1126) 
at java.util.zip.ZipFile$Source.<init>([email protected]/ZipFile.java:963) 
at java.util.zip.ZipFile$Source.get([email protected]/ZipFile.java:933) 
at java.util.zip.ZipFile.<init>([email protected]/ZipFile.java:213) 
at java.util.zip.ZipFile.<init>([email protected]/ZipFile.java:145) 
at java.util.zip.ZipFile.<init>([email protected]/ZipFile.java:159) 
at toposwapper.rules.ZipFileDownloadAction.execute(ZipFileDownloadAction.java:29) 

Đây là phiên bản của tôi về 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) 

Đây là mã mà tôi đang sử dụng để tải về -

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); 
    } 

Ai đó có thể giúp tôi tại sao điều này không thành công?

+3

Vì Java 9 vẫn đang trong giai đoạn thử nghiệm, hãy thử nâng cấp lên phiên bản mới nhất, có lẽ đó chỉ là lỗi trong JDK đã được sửa. Tôi tìm thấy một số ít đề cập đến ngoại lệ này: https://bugs.openjdk.java.net/browse/JDK-8170276 https://bugs.openjdk.java.net/browse/JDK-8172872 –

+0

@AdamMichalik - cảm ơn lời nhắc phản ứng. Vì vậy, trên Ubuntu 16.04 làm thế nào để nâng cấp? :) Chỉ cần cài đặt khác? – gansub

+0

@AdamMichalik - Tùy chọn tốt hơn là cài đặt jdk-8? – gansub

Trả lời

5

Có một vài lỗi (đã đóng) cho Java 9 đề cập đến ngoại lệ này (ví dụ: JDK-8170276, JDK-8172872). Vì Java 9 vẫn đang trong giai đoạn thử nghiệm và bạn đang sử dụng phiên bản từ hơn một năm trước (2016-04-14 so với tháng 7 năm 2017 của thời gian viết), bạn nên nâng cấp lên bản phát hành Java 9 EA mới nhất hoặc dính vào Java 8 cho đến khi phát hành công khai Java 9.

Các vấn đề liên quan