public static void copy(final File src,final File dst) throws IOException {
  if (src == null || !src.exists() || !src.canRead())   throw new IOException("IOException (copy file): source file does not exists or not readable");
  if (!isWritable(dst,true))   throw new IOException("IOException (copy file): destination file not writable");
  Log.w("FileUtils","copying: src: " + src + " to dst: "+ dst);
  final FileInputStream fis=new FileInputStream(src);
  final FileOutputStream fos=new FileOutputStream(dst);
  final InputStream in=new BufferedInputStream(fis);
  final BufferedOutputStream out=new BufferedOutputStream(fos);
  final byte[] buf=new byte[1024];
  int len;
  IOException e=null;
  try {
    while ((len=in.read(buf)) > 0)     out.write(buf,0,len);
  }
 catch (  IOException e1) {
    e=e1;
  }
  try {
    in.close();
  }
 catch (  IOException ignored) {
  }
  try {
    fis.close();
  }
 catch (  IOException ignored) {
  }
  try {
    out.flush();
    out.close();
  }
 catch (  IOException ignored) {
  }
  try {
    fos.flush();
    fos.close();
  }
 catch (  IOException ignored) {
  }
  sync(fos);
  if (e != null)   throw e;
}

public static void copy ( final File src , final File dst ) throws IOException { if ( src == null || ! src . exists ( ) || ! src . canRead ( ) ) throw new IOException ( "IOException (copy file): source file does not exists or not readable" ) ; if ( ! isWritable ( dst , true ) ) throw new IOException ( "IOException (copy file): destination file not writable" ) ; Log . w ( "FileUtils" , "copying: src: " + src + " to dst: " + dst ) ; final FileInputStream fis = new FileInputStream ( src ) ; final FileOutputStream fos = new FileOutputStream ( dst ) ; final InputStream in = new BufferedInputStream ( fis ) ; final BufferedOutputStream out = new BufferedOutputStream ( fos ) ; final byte [ ] buf = new byte [ 1024 ] ; int len ; IOException e = null ; try { while ( ( len = in . read ( buf ) ) > 0 ) out . write ( buf , 0 , len ) ; } catch ( IOException e1 ) { e = e1 ; } try { in . close ( ) ; } catch ( IOException ignored ) { } try { fis . close ( ) ; } catch ( IOException ignored ) { } try { out . flush ( ) ; out . close ( ) ; } catch ( IOException ignored ) { } try { fos . flush ( ) ; fos . close ( ) ; } catch ( IOException ignored ) { } sync ( fos ) ; if ( e != null ) throw e ; }
copies an existing file to another destination
