/**
* 拿到HttpResponse后读取 content-length 头,
* 读取InputStream的时候根据已经读取到的byte数,算出百分比。
*
* @param is
* @param len
* @throws IOException
*/
private static Integer readProgres(InputStream is, int len){
//读取百分比
Integer percentage = 0;
try {
int sizeRead = 0;
byte[] buffer = new byte[1024];
int tmpSize = 0;
do {
sizeRead += tmpSize;
percentage = sizeRead * 100 / len;
tmpSize = is.read(buffer);
} while (tmpSize > 0);
} catch (Exception e) {
e.printStackTrace();
}
return percentage;
}
文件下载并计算进度
最新推荐文章于 2023-09-22 15:57:32 发布