Here you can find the source of copyFile(File source, File destination)
private static void copyFile(File source, File destination) throws IOException
//package com.java2s; import com.google.common.io.Files; import java.io.File; import java.io.IOException; public class Main { private static void copyFile(File source, File destination) throws IOException { Files.copy(source, destination); }/*ww w .j a v a 2 s.co m*/ /** * Copy one file source to a destination. * @param source The file source. * @param destination The new path. * @throws IOException */ public static void copy(File source, File destination) throws IOException { copy(source, destination, false); } /** * Copy one file source to a destination. * @param source The file source. * @param destination The new path. * @param force Should this operation overwrite. * @throws IOException */ public static void copy(File source, File destination, boolean force) throws IOException { if (!source.exists()) { throw new IllegalArgumentException("Source (" + source.getPath() + ") doesn't exist."); } if (!force && destination.exists()) { throw new IllegalArgumentException("Destination (" + destination.getPath() + ") exists."); } if (source.isDirectory()) { copyDirectory(source, destination); } else { copyFile(source, destination); } } private static void copyDirectory(File source, File destination) throws IOException { if (!destination.mkdirs()) { throw new IOException( "Failed to create destination directories"); } File[] files = source.listFiles(); for (File file : files) { if (file.isDirectory()) { copyDirectory(file, new File(destination, file.getName())); } else { copyFile(file, new File(destination, file.getName())); } } } }