public static boolean copyFile(File fromFile,File toFile,boolean forceOverwrite){
  if (fromFile == null || !fromFile.exists() || toFile == null) {
    return false;
  }
  if (toFile.exists() && !forceOverwrite) {
    return false;
  }
  try {
    InputStream fosFrom=new FileInputStream(fromFile);
    OutputStream fosTo=new FileOutputStream(toFile);
    byte bytes[]=new byte[1024];
    int writeSize=0;
    int startIndex=0;
    int readCount=0;
    while ((readCount=fosFrom.read(bytes)) != -1) {
      fosTo.write(bytes,startIndex,readCount);
      writeSize+=(readCount - startIndex);
    }
    fosFrom.close();
    fosTo.close();
    if (writeSize > 0) {
      return true;
    }
 else {
      return false;
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
    return false;
  }
}

public static boolean copyFile ( File fromFile , File toFile , boolean forceOverwrite ) { if ( fromFile == null || ! fromFile . exists ( ) || toFile == null ) { return false ; } if ( toFile . exists ( ) && ! forceOverwrite ) { return false ; } try { InputStream fosFrom = new FileInputStream ( fromFile ) ; OutputStream fosTo = new FileOutputStream ( toFile ) ; byte bytes [ ] = new byte [ 1024 ] ; int writeSize = 0 ; int startIndex = 0 ; int readCount = 0 ; while ( ( readCount = fosFrom . read ( bytes ) ) != - 1 ) { fosTo . write ( bytes , startIndex , readCount ) ; writeSize += ( readCount - startIndex ) ; } fosFrom . close ( ) ; fosTo . close ( ) ; if ( writeSize > 0 ) { return true ; } else { return false ; } } catch ( Exception e ) { e . printStackTrace ( ) ; return false ; } }
copy a file to another one
