URL url = new URL(urls);
URLConnection conn = url.openConnection();
conn.connect();
System.out.println(urls + " 长度:" + conn.getContentLength() / 1024 + "KB");
InputStream fis = conn.getInputStream();
long a = System.currentTimeMillis();
FileOutputStream out = new FileOutputStream(path);
byte buf[] = new byte[10240];
int n;
while ((n = fis.read(buf)) != -1) {
out.write(buf, 0, n);
}
fis.close();
out.close();
long b = System.currentTimeMillis();
System.out.println("[+]: 下载费时:"+ String.valueOf(b-a) + "毫秒");1:怎样得到 每秒下载速度 ?
2:n 是每次读取的字节数吗?

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【cooc123】截止到2008-06-28 11:16:33的历史汇总数据(不包括此帖):
    发帖数:113                发帖分:1450               
    结贴数:34                 结贴分:700                
    未结数:79                 未结分:750                
    结贴率:30.09 %            结分率:48.28 %            
    楼主该结一些帖子了
      

  2.   

    设个标记,没读一次流就加1在开个timer线程,每隔一秒钟读一次标记,请将标记置0标记数*10240(你每次读流的字节数)就是下载速度...