0

ダウンロードがどれだけ進んだかについてprogressBarを更新しようとしている次の方法があります。

private void wget(java.net.URL url, String destination) throws MalformedURLException, IOException {
    java.net.URLConnection conn = url.openConnection();
    java.io.InputStream in = conn.getInputStream();

    File dstfile = new File(destination);
    OutputStream out = new FileOutputStream(dstfile);


    byte[] buffer = new byte[512];
    int length;
    int readBytes = 0;
    while ((length = in.read(buffer)) > 0) {
        out.write(buffer, 0, length);

        // Get progress
        int contentLength = conn.getContentLength();
        if (contentLength != -1) {

            //System.out.println((length / contentLength) * 100); ??
            UpdateForm.progressBar.setValue(2);
        } else {

        }            
    }

    in.close();
    out.close();
}

しかし、私は何%がなくなったかを計算する方法を理解できないようです..

何か案は?

4

0 に答える 0