我正在下载文件并在Expanded Notification栏的视图中显示更新。对于android
如何处理服务器在下载时断开连接的情况?
当读取输入流并且net断开连接时,它应该抛出异常。但它并没有抛出异常。
这段代码是简单的下载循环:
try{
while ( (bufferLength = inputStream.read(buffer)) > 0 )
{
fileOutput.write(buffer, 0, bufferLength);
//add up the size so we know how much is downloaded
downloadedSize += bufferLength;
percent=(int)(100 *( (float)downloadedSize/totalSize ));
Log.i("Downloaded", String.valueOf(downloadedSize) );
}
}
ucon.disconnect();
return 1;
}
catch (IOException e) {
Log.d("Download", "Error: " + e);
return 2;
}
我惊呆了,为什么它不会抛出异常。什么是解决方法?