private static boolean copyFile ( final File aSourceFile , final File aDestFile ) throws IOException { FileOutputStream outputStream = null ; FileInputStream inputStream = null ; boolean success = true ; // destructive copy if ( aDestFile . exists ( ) && ! aDestFile . delete ( ) ) { success = false ; } if ( success && ! aDestFile . createNewFile ( ) ) { LOGGER . warn ( MessageCodes . UTIL_014 , aDestFile . getAbsolutePath ( ) ) ; success = false ; } if ( success ) { try { final FileChannel source ; outputStream = new FileOutputStream ( aDestFile ) ; inputStream = new FileInputStream ( aSourceFile ) ; source = inputStream . getChannel ( ) ; outputStream . getChannel ( ) . transferFrom ( source , 0 , source . size ( ) ) ; } finally { IOUtils . closeQuietly ( outputStream ) ; IOUtils . closeQuietly ( inputStream ) ; } } if ( success && aDestFile . exists ( ) && aSourceFile . canRead ( ) ) { success = aDestFile . setReadable ( true , true ) ; } if ( success && aDestFile . exists ( ) && aSourceFile . canWrite ( ) ) { success = aDestFile . setWritable ( true , true ) ; } if ( success && aDestFile . exists ( ) && aSourceFile . canExecute ( ) ) { success = aDestFile . setExecutable ( true , true ) ; } if ( ! success && ! aDestFile . delete ( ) && LOGGER . isWarnEnabled ( ) ) { LOGGER . warn ( MessageCodes . UTIL_015 , aDestFile ) ; } return success ; }
Copies a non - directory file from one location to another .