这个错误是什么意思?
下面是我的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();
}
答案 0 :(得分:1)
尝试使用此Android HttpsUrlConnection eofexception
看起来你需要添加
if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) { urlConnect.setRequestProperty("Connection", "close"); }
答案 1 :(得分:0)
EOFException表示文件结束(EOF)异常。 EOF用于指示文件的结尾。通常,如果要读取文件直到结束,则执行一段时间操作,条件EOF尚未达到。
它有点类似于字符串末尾的'/ 0'。相反,EOF用于标记文件的结尾
您可能尝试在达到EOF后尝试读取该文件将导致异常被引发
答案 2 :(得分:0)
我的问题是我用来上传文件的网络连接。切换网络连接(到我的LAN wifi网络)后一切正常。 我正在我的本地服务器上测试它,并试图使用除LAN网络之外的外部网络连接上传文件。 希望这会有所帮助。