-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);
}
}
});
}
});
...
エラーが何を意味しているのか、これが何を意味しているのかについて、どのような情報が収集されているのかをまず読まなければなりません。 – JoxTraex