扫码关注官方订阅号
闭关修行中......
拿到HttpResponse后读取 content-length 头,
读取InputStream的时候根据已经读取到的byte数,算出百分比就行了。
糙版代码:
private static void readAndPrintProgress(InputStream is, int len) throws IOException { int sizeRead = 0; byte[] buffer = new byte[1024]; int tmpSize = 0; do { sizeRead += tmpSize; System.out.println((sizeRead * 100 / len) ); tmpSize = is.read(buffer); } while (tmpSize > 0); }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
拿到HttpResponse后读取 content-length 头,
读取InputStream的时候根据已经读取到的byte数,算出百分比就行了。
糙版代码: