如题,直接上源码
- 需要对Java的IO流有一定的了解
- 实现源文件到目标文件的快速拷贝
public static void copyFile(File srcFile,File destFile)throws Exception{
if(!srcFile.exists()){
throw new IllegalArgumentException("File:" + srcFile + "Not exists");
}
else if(!srcFile.isFile()){
throw new IllegalArgumentException(srcFile + "Is Not File");
}
else{
FileInputStream in = new FileInputStream(srcFile);
FileOutputStream out = new FileOutputStream(destFile);
byte []buf = new byte[8*1024];
int b = 0;
while((b = in.read(buf,0,buf.length)) != -1){
out.write(buf,0,b);
out.flush();
}
out.close();in.close();
}
}