HTTPUrlConnection 出现 FileNotFoundException 的问题

来源:互联网 发布:零基础网络运维工程师 编辑:程序博客网 时间:2024/06/10 21:14

URL url = new URL(strUrl);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.getInputStream()



HTTPUrlConnection 在 getInputStream出现 FileNotFoundException 的问题,可能有两种情况:

1. URL中带有中文可能导致这个问题。具体分析待补充。使用 URLEncoder.encode(..)解决。

参看这里 http://blog.csdn.net/berber78/article/details/7245872


2. URL确定OK的话,还是出现FileNotFoundException ,可以看看是否是如下情况:

FileNotFoundException also comes when you get an error message from the server and then try to access getInputStream(). If the Response code is a 400 or above, any call to getInputStream() will throw this error. In this case, you should check getErrorStream() instead. See my answer here.


if ( conn.getResponseCode() >= 400) {    conn.getErrorStream();} else {    conn.getInputStream();}


参看这里:

http://stackoverflow.com/questions/9472425/filenotfoundexception-on-android-version-2-3/18151461#18151461

0 0
原创粉丝点击