我用下面这个代码复制文件,但是为什么每次复制相同文件所使用的时间都不一样呢?- /**
- *
- */
- package com.debug.java;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- /**
- * @author wangpeng
- *
- */
- public class CopyMp3 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- long begin=System.currentTimeMillis();
- copyMp3File();
- long end=System.currentTimeMillis();
- long c=end-begin;
- System.out.println("复制耗时"+c+"毫秒");
- }
- public static void copyMp3File(){
- FileInputStream fis=null;
- FileOutputStream fos=null;
-
- BufferedInputStream bis=null;
- BufferedOutputStream bos=null;
-
- try {
- fis=new FileInputStream("F://test/Up.mp3");
- bis=new BufferedInputStream(fis);
-
- fos=new FileOutputStream("F://test/down.mp3");
- bos=new BufferedOutputStream(fos);
-
- byte[] bt=new byte[1024];
- int len=0;
-
- try {
- while((len=bis.read(bt))!=-1){
- bos.write(bt, 0, len);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }finally{
- try {
- fis.close();
- fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
复制代码 |