Java create directories with Files.createDirectories

The Files.createDirectories creates a new directory; if the parent directories do not exist, they are created as well. The method does not throw an exception if the directory already exists.

Java create directories with Files.createDirectories

The example creates a new directory with Files.createDirectories().
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class JavaCreateDirectories {

    public static void main(String[] args) throws IOException {

        String fileName = "/home/ramesh/docs/newDir";
        Path path = Paths.get(fileName);

        Files.createDirectories(path);
    }
}

Comments