public static File copyFile ( String source , String target ) throws IOException { FileChannel inputChannel = null ; FileChannel outputChannel = null ; try { inputChannel = new FileInputStream ( source ) . getChannel ( ) ; outputChannel = new FileOutputStream ( target ) . getChannel ( ) ; outputChannel . transferFrom ( inputChannel , 0 , inputChannel . size ( ) ) ; } finally { if ( inputChannel != null ) { inputChannel . close ( ) ; } if ( outputChannel != null ) { outputChannel . close ( ) ; } } return new File ( target ) ; }
Copies source file to target .