1
安卓:我從互聯網上使用此方法下載文件: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();
}
的問題是,當互聯網被關閉,讀inoutstream停止一些設備上閱讀,但它繼續閱讀上的其他設備!如何解決這個問題呢?提前致謝。
編輯: 我找到了解決方案,我必須設置一個連接的超時。