我正在努力下载一个软件上的文件,这是我得到的,它的sucesfully下载,我也可以取得进展,但还有一件事,我不知道该怎么做.测量下载速度.我很感激你的帮助.谢谢.
这是当前的下载方法代码
这是当前的下载方法代码
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,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); } } }