(用J**A语言)编写一个应用程序,完成文件的拷贝功能,文件名从命令行得到。

时间:2013.07.02 发布人:jpvr0933

(用J**A语言)编写一个应用程序,完成文件的拷贝功能,文件名从命令行得到。

已解决问题

谷歌jpvr0933用户在2013.07.02提交了关于“直播吧(用J**A语言)编写一个应用程序,完成文件的拷贝功能,文件名从命令行得到。”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-07-29T14:58:11。希望有详细的注释帮助我读懂整个小程序,越详细越好,谢谢各位朋友了!希望大家能够帮助她。

详细问题描述及疑问:希望有详细的注释帮助我读懂整个小程序,越详细越好,谢谢各位朋友了!期待您的答案,你是我的宝贝,你是我的花,谢谢你对我的帮助!

希望以下的回答,能够帮助你。

第1个回答

用户名: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());
}
}