Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要澄清我的Java下载程序吗_Java - Fatal编程技术网

需要澄清我的Java下载程序吗

需要澄清我的Java下载程序吗,java,Java,我自己制作下载程序,目前功能有: A.获取下载大小 BProgressbar C下载时间 D下载速度(不确定) 但我需要澄清以下几点: 下载程序是否使用相同的逻辑从internet下载文件? 我的意思是,在Java中,我们使用FileOutputStream和InputStream。其他人用同样的方法吗 目前我的下载速度估算代码为: while ((bytesRead = reader.read(buffer)) != -1) { writer.write(buffer, 0, bytesR

我自己制作下载程序,目前功能有:
A.获取下载大小
BProgressbar
C下载时间
D下载速度(不确定)

但我需要澄清以下几点:

  • 下载程序是否使用相同的逻辑从internet下载文件? 我的意思是,在Java中,我们使用FileOutputStream和InputStream。其他人用同样的方法吗

  • 目前我的下载速度估算代码为:

    while ((bytesRead = reader.read(buffer)) != -1) {  
    writer.write(buffer, 0, bytesRead);  
      a = (int) (file.length() / 1024);  
      Thread.sleep(1000);  
      csize = (int) (((file.length() / 1024) * 100) / size);  
      progress.setValue(csize);  
      speed.setText("Speed: " + (a - b)+" KB");  
      remaining.setText("Remaining: "+String.valueOf((size - (file.length() / 2014)))+" KB");  
      b = a;  
    }  
    
    我读过这个话题, 但它计算的是总下载时间和速度,而不是每秒的下载速度。我上面的代码显示了每秒的下载速度,但我不确定这是正确的方法

  • 我还在论坛的某个地方读到,如果我将缓冲区从[1024]增加到[2048]或[4096] 这会提高我的下载速度,是真的吗?获得200kb++的速度怎么样?IDM可以做到这一点 对我来说


  • 提前感谢:)

    下载时间为您提供下载速度如果您有文件大小和当前下载量对不起,我没有给出明确的问题,我会更新:)您的代码将下载限制为每秒一个区块,最好尽快下载并测量每个区块之间的时间。