Here you can find the source of copy(File src, File dest)
public static void copy(File src, File dest) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 Red Hat, Inc.//from ww w.j av a2 s. co m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Red Hat Incorporated - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardCopyOption; public class Main { public static void copy(File src, File dest) throws IOException { if (src.isDirectory()) { // ensure destination directory exists if (!dest.exists()) { dest.mkdir(); } // copy all children files recursively String files[] = src.list(); for (String file : files) { File srcFile = new File(src, file); File destFile = new File(dest, file); copy(srcFile, destFile); } } else { // is a file, manually copy the contents over Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); } } }