I am downloading a file and then writing it into sdcard using following code:
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();
Everything is working fine. Normally it takes 2 minutes to download file. If i take out network cable during downloading then seems like it stays in while loop forever. That code is in try catch block but i do not get any exception. Is there anyway to get out of that while loop when network cable is unplugged. Thanks in advance.