Java I/O How to - Create Directories with java.nio.file.Files








Question

We would like to know how to create Directories with java.nio.file.Files.

Answer

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/*w  ww  .j  a v a2 s . c  om*/
public class Main {

  public static void main(String[] args) throws Exception {
    Path directoriesPath = Paths.get("C:/home/test/subtest/subsubtest");
    Path testDirectory = Files.createDirectories(directoriesPath);
    System.out.println("Directory sequence created successfully!");

  }
}

The code above generates the following result.