描述你的问题
越学越糊涂了,这布尔值方法怎么理解呢?看代码,每次在最后return XX;的时候总是有点理解不了,特别是看API的时候......请问用下面这段代码讲解一下,怎么理解这种有布尔值的方法?
这段代码有两个return.....
贴上相关代码
private boolean downURlToStream(String url, OutputStream outputStream) {
BufferedInputStream in = null;
BufferedOutputStream out = null;
HttpURLConnection http = null;
try {
URL url1 = new URL(url);
http = (HttpURLConnection) url1.openConnection();
http.setReadTimeout(3000);
http.setRequestMethod("GET");
in = new BufferedInputStream(http.getInputStream(), 8 * 1024);
out = new BufferedOutputStream(outputStream, 8 * 1024);
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
return true;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (http != null) {
http.disconnect();
}
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
贴上报错信息
贴上相关截图
已经尝试过哪些方法仍然没解决(附上相关链接)
HUX布斯
慕娘9325324
相关分类