为了下载文件,我正在从输入流中读取并写入输出流。在Wifi中,事情很好。但是在下载了几个MB之后的3G网络中,我得到了以下异常。我该如何解决?
-java.net.SocketTimeoutException
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:484)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
at com.android.okhttp.okio.Okio$2.read(Okio.java:140)
at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
at com.android.okhttp.okio.RealBufferedSource.read(RealBufferedSource.java:60)
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:466)
at com.android.okhttp.okio.RealBufferedSource$1.read(RealBufferedSource.java:374)
at com.mtnplay.app.e.b.a(Unknown Source)
at com.mtnplay.app.e.b.a(Unknown Source)
at com.mtnplay.app.e.b.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
答案 0 :(得分:0)
您需要更改ReadTimeout。尝试Socket.setSoTimeout()或HttpURLConnection.setReadTimeout()。