public static void copyDirectory(File source, File destination) throws IOException { copyDirectory(source, destination, null); }
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); }
/** * * This is a convenience method that calls find(File, String, boolean) * with the last parameter set to "false" (does not match directories). * * @see #find(File, String, boolean) * */ public static File find(File contextRoot, String fileName) { return find(contextRoot, fileName, false); }
removeDirectory(file); removeFile(file); pruneEmptyDirectories(file.getParentFile());
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); } } }
removeDirectory(nextFile); removeFile(nextFile);
/** * * This is a convenience method that calls remove(File, boolean) with * the second parameter set to "false" (doesn't prune empty directories). * * @see #remove(File, boolean) * */ public static void remove(File file) throws IOException { remove(file, false); }
public static void copyFile(InputStream input, File destination) throws IOException { OutputStream output = null; try { output = new FileOutputStream(destination); byte[] buffer = new byte[1024]; int bytesRead = input.read(buffer); while (bytesRead >= 0) { output.write(buffer, 0, bytesRead); bytesRead = input.read(buffer); } } finally { if (input != null) close(input); if (output != null) close(output); } }
copyDirectory(source, destination); copyFile(source, destination);
return files[n]; File match = find(files[n], fileName);