try (FileOutputStream fileOutputStream = new FileOutputStream(file, true); InputStream is = response.body().byteStream()) {
while ((len = is.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, len);
downloadLength += len;
downloadInfo.setProgress(downloadLength);
e.onNext(downloadInfo);
}
fileOutputStream.flush();
}
解决方法:
try (FileOutputStream fileOutputStream = new FileOutputStream(file, true); InputStream is = response.body().byteStream()) {
while ((downloadLength != contentLength) && (len = is.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, len);
downloadLength += len;
downloadInfo.setProgress(downloadLength);
e.onNext(downloadInfo);
}
fileOutputStream.flush();
}
downloadLength:已下载长度
contentLength:文件总长度