List of utility methods to do Path Copy nio
void | copyFilesRecursively(final Path from, final Path to) Copies files from from directory to to directory. Preconditions.checkArgument(Files.isDirectory(from), "%s (from) is not a directory"); Preconditions.checkArgument(Files.isDirectory(to), "%s (to) is not a directory"); Files.walkFileTree(from, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path destFile = to.resolve(from.relativize(file)); Files.createDirectories(destFile.getParent()); if (Files.isSymbolicLink(file)) { ... |
void | copyFileToArchive(InputStream srcInputStream, Path destPath) Copy file to archive. Path parent = destPath.getParent(); if (parent != null) { if (Files.notExists(parent)) { Files.createDirectories(parent); Files.copy(srcInputStream, destPath, StandardCopyOption.REPLACE_EXISTING); |
Path | copyFileToDataFolder(ClassLoader cl, String resourceName, Path targetFolder, boolean replace) Copies the given file from the jar to the data folder. if (resourceName == null || "".equals(resourceName)) { throw new IllegalArgumentException("You need to provide a source file name."); if (targetFolder == null) { throw new IllegalArgumentException("The destination is not defined."); Path targetFile = targetFolder.resolve(resourceName); createDirectoriesForFile(targetFile); ... |
void | copyRecursive(Path source, Path target, CopyOption... options) copy Recursive Files.walkFileTree(source, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Files.createDirectories(target.resolve(source.relativize(dir))); return FileVisitResult.CONTINUE; @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { ... |
void | copyRecursively(File fromDirectory, File toDirectory) copy Recursively copyRecursively(fromDirectory, toDirectory, null); |
void | copyRecursively(File src, File dest) copy Recursively copyRecursively(src.toPath(), dest.toPath()); |
void | copyRecursively(File src, File dest) copy Recursively copyRecursively(src.toPath(), dest.toPath()); |
void | copyRecursively(final Path source, final Path destination, final CopyOption... options) Recursively copies one path to another. doCopyRecursively(source, destination, false, options); |
void | copyRecursively(Path source, Path target, AtomicLong bytesCounter, CopyOption... copyOptions) copy Recursively try { if (!Files.exists(source, LinkOption.NOFOLLOW_LINKS)) { throw new RuntimeException("Source path does not exist " + source.toAbsolutePath().toString()); if (!Files.isDirectory(source)) { copyRecursivelyHelper(source, target, bytesCounter, copyOptions); } else { if (Files.exists(target) && !Files.isDirectory(target)) { ... |
void | copyRecursivelyHelper(Path source, Path target, AtomicLong bytesCounter, CopyOption... copyOptions) Assumes that 1) source exists 2) target parent exists try { if (!Files.isDirectory(source)) { Files.copy(source, target, copyOptions); if (bytesCounter != null) { BasicFileAttributes attributes = Files.readAttributes(source, BasicFileAttributes.class); bytesCounter.addAndGet(attributes.size()); } else { ... |