Java Utililty Methods Path Copy nio

List of utility methods to do Path Copy nio

Description

The list of methods to do Path Copy nio are organized into topic(s).

Method

FilecopyResource(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) {
...
voidcopyResource(String source, Path target, Class cls)
Copies class resource to path
try (InputStream is = cls.getResourceAsStream(source)) {
    Files.copy(is, target, REPLACE_EXISTING);
voidcopyResources(final URL source, final Path destination)
Recursively copies the resources specified by the given URL to the destination folder.
doCopyResources(source, destination, false);
voidcopyToDir(Path source, Path targetDir, CopyOption... options)
copy To Dir
Files.copy(source, targetDir.resolve(source.getFileName()), options);
voidcopyTree(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
...
voidcreateDirectories(Path currentRestorePath)
create Directories
try {
    Files.createDirectories(currentRestorePath); 
} catch (IOException ex) {
    throw new IOException("Can't create directory " + currentRestorePath, ex);
voidcreateDirectories(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);
voidcreateDirectories(Path thePath, FileAttribute... theAttributes)
create Directories
if (thePath == null)
    return;
if (fileExtension(thePath) != null) {
    thePath = thePath.getParent();
    if (thePath == null)
        return;
try {
...
voidcreateDirectoriesForFile(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);
voidcreateDirectoriesForOutput(File output)
Create all the directories from an output file
final Path parentDirectory = Paths.get(output.getAbsolutePath()).getParent();
Files.createDirectories(parentDirectory);