A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 黄杨 中级黑马   /  2013-2-3 23:15  /  1351 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 张向辉 于 2013-2-6 14:43 编辑

public class copyTu {
/**
  * @param args
  */
public static void main(String[] args) throws IOException {
  
  long start=System.currentTimeMillis();
  copy();
  long end=System.currentTimeMillis();
  System.out.println((end-start)+"毫秒");
  
}

public static void copy() throws IOException {
  FileInputStream fis=null;
  FileOutputStream fos=null;
  
  fis=new FileInputStream("d:\\My Documents\\My Pictures\\1.jpg");
  fos=new FileOutputStream("d:\\My Documents\\My Pictures\\2.jpg");
   
  byte[] b=new byte[1024];
  int len=0;
  while ((len=fis.read(b))!=-1) {
   fos.write(b, 0, len);
  }
}
}

这代码和老师讲的差不多,编译没问题,但是运行的时候都是打印0毫秒,不知道什么原因。。。

评分

参与人数 1黑马币 +9 收起 理由
Rancho_Gump + 9

查看全部评分

2 个回复

倒序浏览
没问题啊,顺便说声你类名的首字符没大写
回复 使用道具 举报
     朋友,这是计算机的时间精度问题,和你的程序没有关系。我测试过几次,15秒,16秒。偶尔会出现0毫秒的情形。假定计算机的精度就是15毫秒,而你某一次运行的时间小于15毫秒,那么你看到的就有可能是0毫秒。希望我的解答能使你满意。

点评

哦,原来是这样,我说呢  发表于 2013-2-4 22:30

评分

参与人数 1黑马币 +9 收起 理由
Rancho_Gump + 9

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马