private static void _copyFile ( final File srcFile , final File destFile ) throws IOException { if ( destFile . exists ( ) ) { if ( destFile . isDirectory ( ) ) { throw new IOException ( "Destination '" + destFile + "' is a directory" ) ; } } // do copy file FileInputStream input = null ; FileOutputStream output = null ; try { input = new FileInputStream ( srcFile ) ; output = new FileOutputStream ( destFile , false ) ; StreamUtil . copy ( input , output ) ; } finally { StreamUtil . close ( output ) ; StreamUtil . close ( input ) ; } // done if ( srcFile . length ( ) != destFile . length ( ) ) { throw new IOException ( "Copy file failed of '" + srcFile + "' to '" + destFile + "' due to different sizes" ) ; } destFile . setLastModified ( srcFile . lastModified ( ) ) ; }
Internal file copy when most of the pre - checking has passed .