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 が読み取りを停止しても、他のデバイスでは引き続き読み取りを行うことです! この問題を解決するには?前もって感謝します。
編集: 解決策が見つかりました。接続のタイムアウトを設定する必要があります。