public static void copyFiles(final File src,final File dest) throws IOException {
  if (!src.exists()) {
    throw new IOException("Can not find source: " + src.getAbsolutePath());
  }
 else   if (!src.canRead()) {
    throw new IOException("Cannot read: " + src.getAbsolutePath() + ". Check file permissions.");
  }
  final List<String> noCopy=Arrays.asList("org.eclipse.core.runtime","org.eclipse.e4.workbench","org.eclipse.emf.common.ui","org.eclipse.ui.workbench","org.eclipse.xtext.builder");
  if (src.isDirectory()) {
    if (noCopy.contains(src.getName()))     return;
    if (!dest.exists()) {
      if (!dest.mkdirs()) {
        throw new IOException("Could not create direcotry: " + dest.getAbsolutePath());
      }
    }
    final String list[]=src.list();
    if (list != null)     for (int i=0; i < list.length; i++) {
      final File dest1=new File(dest,list[i]);
      final File src1=new File(src,list[i]);
      copyFiles(src1,dest1);
    }
  }
 else {
    final byte[] buffer=new byte[4096];
    int bytesRead;
    try (FileInputStream fin=new FileInputStream(src);FileOutputStream fout=new FileOutputStream(dest)){
      while ((bytesRead=fin.read(buffer)) >= 0) {
        fout.write(buffer,0,bytesRead);
      }
    }
 catch (    final IOException e) {
      final IOException wrapper=new IOException("Unable to copy file: " + src.getAbsolutePath() + "to"+ dest.getAbsolutePath());
      wrapper.initCause(e);
      wrapper.setStackTrace(e.getStackTrace());
      throw wrapper;
    }
  }
}

public static void copyFiles ( final File src , final File dest ) throws IOException { if ( ! src . exists ( ) ) { throw new IOException ( "Can not find source: " + src . getAbsolutePath ( ) ) ; } else if ( ! src . canRead ( ) ) { throw new IOException ( "Cannot read: " + src . getAbsolutePath ( ) + ". Check file permissions." ) ; } final List < String > noCopy = Arrays . asList ( "org.eclipse.core.runtime" , "org.eclipse.e4.workbench" , "org.eclipse.emf.common.ui" , "org.eclipse.ui.workbench" , "org.eclipse.xtext.builder" ) ; if ( src . isDirectory ( ) ) { if ( noCopy . contains ( src . getName ( ) ) ) return ; if ( ! dest . exists ( ) ) { if ( ! dest . mkdirs ( ) ) { throw new IOException ( "Could not create direcotry: " + dest . getAbsolutePath ( ) ) ; } } final String list [ ] = src . list ( ) ; if ( list != null ) for ( int i = 0 ; i < list . length ; i ++ ) { final File dest1 = new File ( dest , list [ i ] ) ; final File src1 = new File ( src , list [ i ] ) ; copyFiles ( src1 , dest1 ) ; } } else { final byte [ ] buffer = new byte [ 4096 ] ; int bytesRead ; try ( FileInputStream fin = new FileInputStream ( src ) ; FileOutputStream fout = new FileOutputStream ( dest ) ) { while ( ( bytesRead = fin . read ( buffer ) ) >= 0 ) { fout . write ( buffer , 0 , bytesRead ) ; } } catch ( final IOException e ) { final IOException wrapper = new IOException ( "Unable to copy file: " + src . getAbsolutePath ( ) + "to" + dest . getAbsolutePath ( ) ) ; wrapper . initCause ( e ) ; wrapper . setStackTrace ( e . getStackTrace ( ) ) ; throw wrapper ; } } }
this function will copy files or directories from one location to another . note that the source and the destination must be mutually exclusive . this function can not be used to copy a directory to a sub directory of itself . the function will also have problems if the destination files already exist .
