监测文件下载成功

来源:互联网 发布:java ftp下载文件夹 编辑:程序博客网 时间:2024/06/02 17:40
 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);
    } 
0 0