public static boolean copyFile(File file,File copy){
  if (file == null || copy == null)   throw new NullPointerException("File cannot be null");
  if (!file.isFile() || copy.isDirectory())   throw new IllegalArgumentException("Not a valid file");
  FileInputStream fis=null;
  FileOutputStream fos=null;
  try {
    fis=new FileInputStream(file);
    fos=new FileOutputStream(copy);
    int bytes;
    byte[] packet=new byte[COPY_PACKET_SIZE];
    while ((bytes=fis.read(packet,0,COPY_PACKET_SIZE)) != -1)     fos.write(packet,0,bytes);
    return true;
  }
 catch (  Exception e) {
    LOGGER.log(Level.SEVERE,"Error copying file",e);
    return false;
  }
 finally {
    try {
      if (fos != null)       fos.close();
    }
 catch (    Exception e) {
      LOGGER.log(Level.SEVERE,"Problem closing target stream",e);
    }
    try {
      if (fis != null)       fis.close();
    }
 catch (    Exception e) {
      LOGGER.log(Level.SEVERE,"Problem closing source stream",e);
    }
  }
}

public static boolean copyFile ( File file , File copy ) { if ( file == null || copy == null ) throw new NullPointerException ( "File cannot be null" ) ; if ( ! file . isFile ( ) || copy . isDirectory ( ) ) throw new IllegalArgumentException ( "Not a valid file" ) ; FileInputStream fis = null ; FileOutputStream fos = null ; try { fis = new FileInputStream ( file ) ; fos = new FileOutputStream ( copy ) ; int bytes ; byte [ ] packet = new byte [ COPY_PACKET_SIZE ] ; while ( ( bytes = fis . read ( packet , 0 , COPY_PACKET_SIZE ) ) != - 1 ) fos . write ( packet , 0 , bytes ) ; return true ; } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Error copying file" , e ) ; return false ; } finally { try { if ( fos != null ) fos . close ( ) ; } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Problem closing target stream" , e ) ; } try { if ( fis != null ) fis . close ( ) ; } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Problem closing source stream" , e ) ; } } }
copies source file to the destination file , returns true if the file was successfully copied .
