2016-05-19 6 views
-2

こんにちは、私はウェブからzipファイルをダウンロードしてSDカードに保存しています。 私はjava.net.SocketTimeoutExceptionを得続けます。Androidダウンロードzipファイルエラー(ioエラー)

エラー:

io error: java.net.SocketTimeoutException 
    at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488) 
    at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37) 
    at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237) 
    at okio.Okio$2.read(Okio.java:139) 
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:211) 
    at okio.RealBufferedSource.read(RealBufferedSource.java:50) 
    at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:381) 
    at okio.RealBufferedSource$1.read(RealBufferedSource.java:371) 
    at java.io.DataInputStream.read(DataInputStream.java:63) 
    at java.io.InputStream.read(InputStream.java:162) 
    at java.io.DataInputStream.read(DataInputStream.java:59) 
    at com.my.app.SyncFragment$25$1.onResponse(SyncFragment.java:3473) 
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133) 
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
    at java.lang.Thread.run(Thread.java:818) 

マイコード:手始めに

... 
//New Request 
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); 
logging.setLevel(HttpLoggingInterceptor.Level.BASIC); 
final OkHttpClient client = new OkHttpClient.Builder() 
     .addInterceptor(logging) 
     .build(); 


if (Utils.isConnectedToInternet(getActivity())) 
    AsyncTask.execute(new Runnable() { 
     @Override 
     public void run() { 

      client 
        .newCall(getRequest(url)) 
        .enqueue(new Callback() { 
         @Override 
         public void onFailure(Call call, IOException e) { 
          e.printStackTrace(); 
         } 

         @Override 
         public void onResponse(Call call, Response response) throws IOException { 
          if (!response.isSuccessful()) 
           throw new IOException("Unexpected code " + response); 

          try { 

           InputStream ins = response.body().byteStream(); 
           DataInputStream dis = new DataInputStream(ins); 

           byte[] buffer = new byte[1024]; 
           int length; 


           FileOutputStream fos = new FileOutputStream(new File(folderPath + "/" + filename + ".zip")); 
           while ((length = dis.read(buffer)) > 0) { //ERROR FROM THIS LINE* 
            fos.write(buffer, 0, length); 
           } 

          } catch (MalformedURLException mue) { 
           Log.e("SYNC downloadZipFile", "malformed url error: ", mue); 
          } catch (IOException ioe) { 
           Log.e("SYNC downloadZipFile", "io error: ", ioe); 
          } catch (SecurityException se) { 
           Log.e("SYNC downloadZipFile", "security error: ", se); 
          } catch (Exception e) { 
           Log.e("SYNC downloadZipFile", "Exception: ", e); 
          } 
         } 
        }); 
     } 
    }); 
    ... 
+0

エラーが何を意味しているのか、これが何を意味しているのかについて、どのような情報が収集されているのかをまず読まなければなりません。 – JoxTraex

答えて

0

、あなたが実際に質問をしていなかったが、私はあなたがどのようなエラー手段を知りたいと仮定。

タイムアウト例外は、通常、応答をまったく受信していないことを意味します。 https://docs.oracle.com/javase/7/docs/api/java/net/SocketTimeoutException.html

入力ファイル(http://またはwww)に間違いがないことを確認してください。チェックポートも開いています。これは、ポートがブロックされている場合に発生しますサーバー側。可能であれば、よりローカルのマシンで別のファイルを試してみてください。

関連する問題