List of utility methods to do Directory Copy nio
void | copyDir(File dir1, File dir2) copy Dir if (!dir1.isDirectory()) throw new IOException("Not a directory: " + dir1); if (dir2.exists()) throw new IOException("Cannot copy to existing directory: " + dir2); dir2.mkdirs(); File[] files = dir1.listFiles(); if (files != null) { for (File f : files) { ... |
void | copyDir(File sourceDir, File targetDir) copy Dir if (targetDir.exists()) { if (!targetDir.isDirectory()) { throw new IOException("Not a directory " + targetDir.getAbsolutePath()); } else if (!targetDir.mkdirs()) { throw new IOException("Failed to create directory " + targetDir.getAbsolutePath()); File[] children = sourceDir.listFiles(); ... |
void | copyDir(final Path fromPath, final Path toPath) copy Dir toPath.toFile().mkdirs(); Files.walkFileTree(fromPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path targetPath = toPath.resolve(fromPath.relativize(dir)); if (!Files.exists(targetPath)) { Files.createDirectory(targetPath); return FileVisitResult.CONTINUE; @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, toPath.resolve(fromPath.relativize(file)), StandardCopyOption.REPLACE_EXISTING); return FileVisitResult.CONTINUE; }); |
void | copyDir(final String src, final String dest) copy Dir copyDir(new File(src), new File(dest)); |
void | copyDir(Path from, Path to, IProgressMonitor monitor) copy Dir Files.walkFileTree(from, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path targetdir = to.resolve(from.relativize(dir)); try { Files.copy(dir, targetdir); ... |
void | copyDir(String sourceDir, String targetDir) copy files from directory sourceDirOrFile to directory targetDirOrFile File sDir = new File(sourceDir); File tDir = new File(targetDir); if (!tDir.exists()) { tDir.mkdirs(); if (sDir.exists()) { if (sDir.isDirectory()) { File[] files = sDir.listFiles(); ... |
void | copyDir(String src, String dst) copy Dir copyDir(new File(src), new File(dst)); |
void | copyDirectiory(String sourceDir, String targetDir) copy Directiory (new File(targetDir)).mkdirs(); File[] file = (new File(sourceDir)).listFiles(); for (int i = 0; i < file.length; i++) { if (file[i].isFile()) { File sourceFile = file[i]; File targetFile = new File( new File(targetDir).getAbsolutePath() + File.separator + file[i].getName()); copyFile(sourceFile, targetFile); ... |
void | copyDirectory(File in, File out) copy Directory copyDirectory(in, out, Collections.<String>emptySet()); |
void | copyDirectory(File in, File out) copy Directory copyDirectory(in, out, Collections.<String>emptySet()); |