0

这个错误是什么意思?

以下是我的 logcat 输出:

01-23 17:09:29.120: W/System.err(24339): java.io.EOFException
01-23 17:09:29.120: W/System.err(24339):    at libcore.io.Streams.readAsciiLine(Streams.java:203)
01-23 17:09:29.120: W/System.err(24339):    at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:544)
01-23 17:09:29.120: W/System.err(24339):    at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:784)
01-23 17:09:29.120: W/System.err(24339):    at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
01-23 17:09:29.120: W/System.err(24339):    at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
01-23 17:09:29.130: W/System.err(24339):    at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:270)
01-23 17:09:29.130: W/System.err(24339):    at com.sfcca.coverflow.Store$downloadMagazine.doInBackground(Store.java:881)
01-23 17:09:29.130: W/System.err(24339):    at com.sfcca.coverflow.Store$downloadMagazine.doInBackground(Store.java:1)
01-23 17:09:29.130: W/System.err(24339):    at android.os.AsyncTask$2.call(AsyncTask.java:264)
01-23 17:09:29.130: W/System.err(24339):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-23 17:09:29.130: W/System.err(24339):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-23 17:09:29.130: W/System.err(24339):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
01-23 17:09:29.130: W/System.err(24339):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-23 17:09:29.130: W/System.err(24339):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-23 17:09:29.130: W/System.err(24339):    at java.lang.Thread.run(Thread.java:856)

根据 logcat,这是代码的一部分,其中存在错误:我正在尝试从服务器检索图像 url,然后下载它们

try {
                    HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
                    conn.setDoInput(true);
                    conn.connect();
                    InputStream in = conn.getInputStream();
                    Log.i("im connected", "Download");
                    bmImg = BitmapFactory.decodeStream(in);

                    File filename;
                    try {
                         // GET EXTERNAL STORAGE, SAVE FILE THERE
                        File storagePath = new File(Environment.getExternalStorageDirectory(),"/Futsing/issue"+issueNumber+"/");
                        storagePath.mkdirs();

                        filename = new File(storagePath + "/page"+number+".jpg");
                        FileOutputStream out = new FileOutputStream(filename);
                        bmImg.compress(Bitmap.CompressFormat.JPEG, 90, out);

                        out.flush();
                        out.close();
                        in.close();
                        MediaStore.Images.Media.insertImage(getContentResolver(),filename.getAbsolutePath(), filename.getName(),
                                filename.getName());          


                         // displayImage();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }   
                } catch (IOException e) {
                    e.printStackTrace();
                }
4

3 回答 3

1

试试这个Android HttpsUrlConnection eofexception

看起来你需要添加

if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) { urlConnect.setRequestProperty("Connection", "close"); }
于 2014-01-24T05:13:02.690 回答
0

EOFException 表示文件结束 (EOF) 异常。EOF 用于指示文件的结束。通常,如果您想读取文件直到最后,您会在未达到 EOF 条件的情况下执行一段时间操作。

它有点类似于字符串末尾的“/0”。EOF 用于标记文件的结尾

您可能会在达到 EOF 后尝试读取文件,这将导致引发异常

于 2013-01-23T09:28:41.127 回答
0

我的问题是我用于上传文件的网络连接。切换网络连接(到我的 LAN wifi 网络)后一切正常。我在本地服务器上对其进行测试,并尝试使用 LAN 网络以外的外部网络连接上传文件。希望这可以帮助。

于 2018-05-31T11:12:24.670 回答