1

私がその自動更新を持っているプログラムでは、特定のファイルをダウンロードする必要があり(すでに動作しています)、次のコードでそれを行います:

public static void getFile() {
    try {
        URL url = new URL("https://dl.dropboxusercontent.com/s/tc301v61zt0v5cd/texture_pack.png?dl=1");
        InputStream in = new BufferedInputStream(url.openStream());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        int n = 0;
        while (-1 != (n = in.read(buf))) {
            out.write(buf, 0, n);
        }
        out.close();
        in.close();
        byte[] response = out.toByteArray();
        FileOutputStream fos = new FileOutputStream(file4);
        fos.write(response);
        fos.close();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Check your internet connection, then try again.\nOr re-install the program.\nError Message 7", "Could Not Download The Required Resources.", JOptionPane.NO_OPTION);
        e.printStackTrace();
        System.exit(0);
    }
}

ダウンロードの現在の完了状況 (ダウンロードされた割合など) を取得し、それを整数にしてコンソールに出力する方法を実装するにはどうすればよいでしょうか (開発者のテストのためだけに)。また、ダウンロードの推定残り時間を取得するには、どのような式を使用できますか? 何でも役に立ちます!ありがとう。

4

2 に答える 2