Java Path Copy nio createDirectoryIfNotExists(Path path)

Here you can find the source of createDirectoryIfNotExists(Path path)

Description

Check specified directory.

License

Apache License

Parameter

Parameter Description
path path to this directory.

Exception

Parameter Description
IOException if directories cannot be created.

Declaration

public static void createDirectoryIfNotExists(Path path) throws IOException 

Method Source Code


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

import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;

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

public class Main {
    /**/*from  w  w w .j  a v  a2s  . c om*/
     * Check specified directory.
     *
     * @param path path to this directory.
     * @throws IOException if directories cannot be created.
     */
    public static void createDirectoryIfNotExists(Path path) throws IOException {
        try {
            Files.createDirectories(path);
        } catch (FileAlreadyExistsException ignored) {
        }
    }
}

Related

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