我有使用以下doInBackground
方法的 AsyncTask 。这应该是读取和写入流。问题是当连接断开时 IOException 在buffer
为空之前被调用(它在之前离开while
循环len != -1
),我想避免这种情况。
protected Boolean doInBackground(String... StringUrls) {
try {
// ...
len = in.read(buffer);
while (len != -1) {
bufOutstream.write(buffer, 0, len);
len = in.read(buffer);
if (Recorder.this.isCancelled) {
Recorder.this.stopSelf();
break;
}
}
bufOutstream.close();
} catch (IOException e) {
System.err.println("Caught IOException: " + e.getMessage());
//
}
return true;
}