【发布时间】:2012-08-22 14:35:27
【问题描述】:
Android:我正在使用这种方法从互联网下载文件:
InputStream in = null;
try {
in = connection.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
byte[] buffer = new byte[1024];
int length = 0;
try {
while ((length = in.read(buffer)) != -1) {
try {
fout.write(buffer, 0, length);
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
try {
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
问题是当网络关闭时,read inoutstream 在某些设备上停止读取,但在其他设备上继续读取!如何解决这个问题呢?提前致谢。
编辑: 我找到了解决办法,我必须设置一个连接的超时时间。
【问题讨论】:
标签: android download inputstream