public static void copyFile(File source, File destination) throws IOException { // // if the destination is a dir, what we really want to do is create // a file with the same name in that dir // if (destination.isDirectory()) destination = new File(destination, source.getName()); FileInputStream input = new FileInputStream(source); copyFile(input, destination); }
public static void copyDirectory(File source, File destination, FileFilter filter) throws IOException { File nextDirectory = new File(destination, source.getName()); // // create the directory if necessary... // if (!nextDirectory.exists() && !nextDirectory.mkdirs()) { Object[] filler = { nextDirectory.getAbsolutePath() }; String message = _MESSAGES.get("DirCopyFailed", filler); throw new IOException(message); } File[] files = source.listFiles(); // // and then all the items below the directory... // for (int n = 0; n < files.length; ++n) { if (filter == null || filter.accept(files[n])) { if (files[n].isDirectory()) copyDirectory(files[n], nextDirectory, filter); else copyFile(files[n], nextDirectory); } } }
copyFile(source, destination);