ファイルをダウンロードし、次のコードを使用して SD カードに書き込みます。
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
File file = new File(Environment.getExternalStorageDirectory()+"/MyProject/data");
FileOutputStream fos = new FileOutputStream(file);
int inByte;
while((inByte = is.read()) != -1){
fos.write(inByte);
System.out.println("in while loop inByte: "+inByte);
}
fos.close();
is.close();
すべてが正常に機能しています。通常、ファイルのダウンロードには 2 分かかります。ダウンロード中にネットワークケーブルを外すと、ループが永遠に続くようです。そのコードは try catch ブロックにありますが、例外は発生しません。ネットワークケーブルが抜かれているときにループから抜け出す方法はありますか。前もって感謝します。