io Copy

package family;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class File_aryCopy {
 public static void main(String[] args) {
   copy_file(new File("e:/a/b.doc"), new File("f:/b/b.doc"));
  }
  
  public static void copy_file(File resource,File dest){
   try {
    FileInputStream fis=new FileInputStream(resource);
    FileOutputStream fos=new FileOutputStream(dest);
    
    long start=System.currentTimeMillis();//计时
    int size;
    byte [] bytes=new byte[1800];
    while((size=fis.read(bytes,0,bytes.length))!=-1){
     fos.write(bytes,0,size);
    }
    
    long end=System.currentTimeMillis();
    System.out.println(end-start);
   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   
  }
}

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页