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 ,可以看看是否是如下情况:
a 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