用户名:dance_qian
publicstaticvoidcopyFile(FilesrcFile,FiledestFile,
boole套宗看套宽酒济anpreserveFile首Date)throwsIOException{
if(srcFile==**ll){
throw院校煤绝newNullPointerException("Sourcemustnotbe**ll");
}
if(destFile==**ll){
thrownewNullPointerEx照陈己迫常准ception("Destinationmustnotbe**ll");
}
if(srcFile.exists()==fal束判名顶创守se){
thrownewFileNotFoundException("Source'"+srcFile+"'doesnotexist");
}
if(srcFile.isDirectory()){
thrown效病而握威粒火营ewIOExcepti滑零错医约景两广主施on("Source'"+srcFile+"'existsbut山许福确茶isadirectory");
}
i判f(srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())){
thrownewIOException("Source'"+srcFile+"'anddestination'"+destFile+"'arethesame");
}
i李理古限普案写基全散f(destFile.getParentFile()!=**ll&&destFile.getParentFile().exists()==false){
if(destFile.getParentFile().mkdirs()==false){
thrownewIOException("Destination'"+destFile+"'directoryca判差入虽nnotbecre知很展ated");
}
}
if(destFile.exists()&&destFile.笔游否送见普谈革既canWrite()==false){
thrownewIOException("Destination'"+destFile+"'existsbutisread-only春充验去支问终毫被呢");
}
doCopyFile(srcFile,destFi蒸成克机副征le,preserveFileDate);
}
/**
*Internalcopyfilemethod.
*
*先且@paramsrcFil怀宪兵镇影台际半草车ethevalidated厚得命怀若sourcefile,mustnotbe<code>**ll</code>
*@paramdestFilethevalidateddestinationfile,mustnotbe<code>**ll</code>
*@parampreserveFileDatewhethertopreservethefiledate
*@throwsIOExceptionifanerroroccurs
*/
privatestaticvoiddoCopyFile(FilesrcFile,FiledestFile,booleanpreserveFileDate)throwsIOException{
if(destFile.exists()&&destFile.isDirectory()){
thrownewIOException("Destination'"+destFile+"'existsbutisadirectory");
}
FileInputStreaminput=newFileInputStream(srcFile);
try{
FileOutputStreamoutput=newFileOutputStream(destFile);
try{
IOUtils.copy(input,output);
}finally{
IOUtils.closeQuietly(output);
}
}finally{
IOUtils.closeQuietly(input);
}
if(srcFile.length()!=destFile.length()){
thrownewIOException("Failedtocopyfullcontentsfrom'"+
srcFile+"'to'"+destFile+"'");
}
if(preserveFileDate){
destFile.setLastModified(srcFile.lastModified());
}
}