Here you can find the source of copyFiles(File fromDir, File toDir)
public static void copyFiles(File fromDir, File toDir) throws IOException
//package com.java2s; /*-//from w ww.j a va2 s . co m * See the file LICENSE for redistribution information. * * Copyright (c) 2002, 2011 Oracle and/or its affiliates. All rights reserved. * */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { /** * Copies all files in fromDir to toDir. Does not copy subdirectories. */ public static void copyFiles(File fromDir, File toDir) throws IOException { String[] names = fromDir.list(); if (names != null) { for (int i = 0; i < names.length; i += 1) { File fromFile = new File(fromDir, names[i]); if (fromFile.isDirectory()) { continue; } File toFile = new File(toDir, names[i]); int len = (int) fromFile.length(); byte[] data = new byte[len]; FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(fromFile); fos = new FileOutputStream(toFile); fis.read(data); fos.write(data); } finally { if (fis != null) { fis.close(); } if (fos != null) { fos.close(); } } } } } }