Java写的检索文件&合并文件功能(二)

2014-11-24 11:33:07 · 作者: · 浏览: 13
}
}
}
/**
* Copy the file from f1 to f2sa
* @param f1
* @param f2
* @return
* @throws Exception
*/
public long fileCopy(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);
}
}
}