List of utility methods to do Path Copy nio
File | copyResource(String resourceLocation, Path target) copy Resource try { InputStream stream = ClassLoader.getSystemResourceAsStream(resourceLocation); if (stream == null) { throw new RuntimeException("Can't locate: " + resourceLocation); Files.copy(stream, target, StandardCopyOption.REPLACE_EXISTING); return target.toFile(); } catch (IOException e) { ... |
void | copyResource(String source, Path target, Class> cls) Copies class resource to path try (InputStream is = cls.getResourceAsStream(source)) {
Files.copy(is, target, REPLACE_EXISTING);
|
void | copyResources(final URL source, final Path destination) Recursively copies the resources specified by the given URL to the destination folder. doCopyResources(source, destination, false); |
void | copyToDir(Path source, Path targetDir, CopyOption... options) copy To Dir Files.copy(source, targetDir.resolve(source.getFileName()), options); |
void | copyTree(final Path source, final Path target) Recursively copy the contents of source into the target; target does not have to exist, it can exist. if (!Files.exists(source)) { throw new IOException(String.format("Can not copy: source directory %s does not exist", source.toAbsolutePath().toString())); Files.createDirectories(target); Files.walkFileTree(source, new SimpleFileVisitor<Path>() { Path currentTarget = target; @Override ... |
void | createDirectories(Path currentRestorePath) create Directories try { Files.createDirectories(currentRestorePath); } catch (IOException ex) { throw new IOException("Can't create directory " + currentRestorePath, ex); |
void | createDirectories(Path path, FileAttribute>... attrs) create Directories try { Files.createDirectories(path, attrs); } catch (IOException ex) { throw new RuntimeException("Failed to create directory " + path.toAbsolutePath().toString(), ex); |
void | createDirectories(Path thePath, FileAttribute>... theAttributes) create Directories if (thePath == null) return; if (fileExtension(thePath) != null) { thePath = thePath.getParent(); if (thePath == null) return; try { ... |
void | createDirectoriesForFile(Path file) Creates all missing directories for the current path. Path parent = file.getParent(); try { Files.createDirectories(parent); } catch (IOException e) { throw new RuntimeException(e); |
void | createDirectoriesForOutput(File output) Create all the directories from an output file final Path parentDirectory = Paths.get(output.getAbsolutePath()).getParent();
Files.createDirectories(parentDirectory);
|