- 
                Notifications
    You must be signed in to change notification settings 
- Fork 4
Java create directories with Files.createDirectories
        Ramesh Fadatare edited this page Jul 11, 2019 
        ·
        1 revision
      
    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.
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);
    }
}