Blankj / Blankj/AndroidUtilCode

FileIOUtils#writeFileFromIS 这个方法计算进度时出现了除0的问题

Open
#1,481 0 comments 0 reactions 1 assignee Claimed by @Blankj View on GitHub
bug
Dominant language
Java
Stars
33.6k
Forks
10.6k
PR merge metrics
No merged PRs in 30d

Description

## 描述 Bug

简洁地描述下 Bug。
com.blankj.utilcode.util.FileIOUtils#writeFileFromIS 这个方法计算进度时出现了除0,导致计算出的进度为infinity.
我是结合Retrofit来进行下载,相关代码附在了下面。但发现此工具类不能正确读出总长度,也不能传入总长度值。

- AndroidUtilCode 的版本:'com.blankj:utilcodex:1.30.5'
- 出现 Bug 的设备型号:全部
- 设备的 Android 版本:全部

## 相关代码

```java
ResponseBody responseBody = response.body();
long total = responseBody.contentLength();
boolean writtenToDisk =FileIOUtils.writeFileFromIS(savePath, responseBody.byteStream(), new FileIOUtils.OnProgressUpdateListener() {
@Override
public void onProgressUpdate(double progress) {
retrofitCallBack.onProgress(total, (long) (total*progress),progress,true);
}
});
```
-->
```
put your code here
```

## 异常堆栈

未报异常,但得出的值为infinity

```
put the stack of crash here
```

## 截图

![image](https://user-images.githubusercontent.com/1248528/114694613-4aecaf00-9d4d-11eb-88af-ed6b9b2059bb.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.