private InputStream getInputStreamFromUrl(String urlStr) throws IOException {
URL url = null;
url = new URL(urlStr);
HttpURLConnection urlConnection = null;
urlConnection = (HttpURLConnection)url.openConnection(); InputStream inputStream = urlConnection.getInputStream();//这一行返回值总是为空
return inputStream;
}我在模拟器上添加一个下载按钮,用来下载mp3文件,可是在上面的代码中inputStream 总是为空,为什么?
URL url = null;
url = new URL(urlStr);
HttpURLConnection urlConnection = null;
urlConnection = (HttpURLConnection)url.openConnection(); InputStream inputStream = urlConnection.getInputStream();//这一行返回值总是为空
return inputStream;
}我在模拟器上添加一个下载按钮,用来下载mp3文件,可是在上面的代码中inputStream 总是为空,为什么?
然后检查url的可用性
2、如果获取不到数据流,比如
InputStream inputStream = urlConnection.getInputStream();//这一行返回值总是为空
可能是模拟器或者手机网络不通造成的
3、下载的得到的东西size不对
可能是输入流和输出流读写的时候,没有指定偏移量和最大字节数导致的。