public static void copy(File source,File dest) throws IOException {
  if (source.isDirectory()) {
    dest.mkdir();
    for (    File child : listFiles(source)) {
      copy(child,new File(dest,child.getName()));
    }
  }
 else {
    if (source.exists()) {
      long lm=source.lastModified();
      if (dest.isDirectory()) {
        dest=new File(dest,source.getName());
      }
      FileOutputStream fos=new FileOutputStream(dest);
      try {
        FileInputStream fis=new FileInputStream(source);
        try {
          if (USE_NIO) {
            nioCopy(fos,fis);
          }
 else {
            oioCopy(source,fos,fis);
          }
        }
  finally {
          fis.close();
        }
      }
  finally {
        fos.close();
      }
      dest.setExecutable(source.canExecute(),true);
      dest.setLastModified(lm);
    }
  }
}

public static void copy ( File source , File dest ) throws IOException { if ( source . isDirectory ( ) ) { dest . mkdir ( ) ; for ( File child : listFiles ( source ) ) { copy ( child , new File ( dest , child . getName ( ) ) ) ; } } else { if ( source . exists ( ) ) { long lm = source . lastModified ( ) ; if ( dest . isDirectory ( ) ) { dest = new File ( dest , source . getName ( ) ) ; } FileOutputStream fos = new FileOutputStream ( dest ) ; try { FileInputStream fis = new FileInputStream ( source ) ; try { if ( USE_NIO ) { nioCopy ( fos , fis ) ; } else { oioCopy ( source , fos , fis ) ; } } finally { fis . close ( ) ; } } finally { fos . close ( ) ; } dest . setExecutable ( source . canExecute ( ) , true ) ; dest . setLastModified ( lm ) ; } } }
copy a file from the source file to the destination file . if the source is a directory , it will be copied recursively . note that unlike unix cp , if the destination is directory , the source * contents * will be copied to the destination * contents * , not as a subdirectory of dest .
