天天看点

在读取流的时候的异常java.io.EOFException

今天一个在学习android的同学遇到了这个问题,上网都是socket方面的,但是他的这个却不是,然后我看了他的代码,因为我自己没有遇到过这个问题

java.io.eofexception:

            就是表示输入过程中意外地到达文件尾或流尾的信号,导致从session中获取数据失败 既然读取的时候意外 的到了尾部,那么是不是流里边就没有内容呢?然后我读他的代码才发现, public inputstream getinputstreamfromurl(string urlstr) throws malformedurlexception, ioexception { url url = new url(urlstr); httpurlconnection urlconn = (httpurlconnection)url.openconnection(); inputstream inputstream = urlconn.getinputstream(); filesize = urlconn.getcontentlength() / (1024); return inputstream; } 他的httpurlconnection 只是打开了,但是却没有连接,最后加一句urlconn .connect(); 也就ok了。

继续阅读