首页 > 代码库 > java复制文件

java复制文件

package com.test.tes;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.util.Date;/** * 复制文件到指定目录下 * @author Wdnncey * */public class Copy {         public static long forJava(File f1,File f2) throws Exception{          long time=new Date().getTime();          int length=2097152;          FileInputStream in=new FileInputStream(f1);          FileOutputStream out=new FileOutputStream(f2);          byte[] buffer=new byte[length];          while(true){           int ins=in.read(buffer);           if(ins==-1){            in.close();            out.flush();            out.close();            return new Date().getTime()-time;           }else            out.write(buffer,0,ins);          }         }        public static void main(String[] args) {        try {            forJava(new File("1.zip"), new File("e:\\a\\b\\2.zip"));        } catch (Exception e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }}

 

java复制文件