java 下载速度计算 |
您所在的位置:网站首页 › java上传下载速度怎么计算的 › java 下载速度计算 |
我正在下载软件上的文件,这就是我所得到的,它可以成功下载,并且我也可以取得进展,但是还有1件事我不知道该怎么做。测量下载速度。多谢您的协助。谢谢。这是当前的下载方法代码 public void run() { OutputStream out = null; URLConnection conn = null; InputStream in = null; try { URL url1 = new URL(url); out = new BufferedOutputStream( new FileOutputStream(sysDir+"\\"+where)); conn = url1.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; double progress1; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; this.speed= (int) (((double) buffer.length)/8); progress1 = (double) numWritten; this.progress=(int) progress1; } } catch (Exception ex) { echo("Unknown Error: " + ex); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ex) { echo("Unknown Error: " + ex); } } } |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |