Java Path Copy nio createDirectoryRecursively(Path dir)

Here you can find the source of createDirectoryRecursively(Path dir)

Description

Attempts to create a directory given a String path.

License

Apache License

Parameter

Parameter Description
dir a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void createDirectoryRecursively(Path dir)
        throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
    /**//from  www .jav  a 2 s .co  m
     * Attempts to create a directory given a String path.
     * 
     * @param dir
     * @throws IOException
     */
    public static void createDirectoryRecursively(Path dir)
            throws IOException {

        // Attempt to create a directory
        try {
            Files.createDirectories(dir);
        } catch (IOException e) {
            throw new IOException(
                    "Exception while trying to create directory: " + e);
        }

        // Verify the directory was successfully created
        if (!dir.toFile().exists()) {
            throw new IOException(
                    "Failed to verify directory creation - directory does not exist.");
        }

    }
}

Related

  1. createDirectoriesIfNotExists(Path path)
  2. createDirectory(Path directory)
  3. createDirectory(Path outDir, boolean cleanExisting)
  4. createDirectory(Path parent, String name)
  5. createDirectoryIfNotExists(Path path)
  6. createDirectoryRecursively(String dirName)
  7. renameTo(Path from, Path to, CopyOption... options)
  8. write(InputStream in, Path path, StandardCopyOption op)