public static boolean move ( String sourcePath , String targetPath ) throws IllegalArgumentException { Params . notNull ( sourcePath , "Source path" ) ; Params . notNull ( targetPath , "Target path" ) ; File sourceFile = new File ( sourcePath ) ; if ( ! sourceFile . exists ( ) ) { log . error ( "Missing file to move |%s|." , sourcePath ) ; return false ; } File targetFile = new File ( targetPath ) ; if ( targetFile . exists ( ) ) { log . debug ( "Target file exists |%s|. File moving aborted." , targetPath ) ; return false ; } return sourceFile . renameTo ( targetFile ) ; }
Move source file to requested destination but do not overwrite . This method takes care to not overwrite destination file and returns false if it already exists . Note that this method does not throw exceptions if move fails and caller should always test returned boolean to determine if operation completes .