Java Examples - Create directories recursively

Advertisements


Problem Description:

How to create directories recursively ?

Solution:

Following example shows how to create directories recursively with the help of file.mkdirs() methods of File class.

import java.io.File;

public class Main {
   public static void main(String[] args) {
      String directories = "D:\\a\\b\\c\\d\\e\\f\\g\\h\\i";
      File file = new File(directories);
      boolean result = file.mkdirs();
      System.out.println("Status = " + result);
   }
}

Result:

The above code sample will produce the following result.

Status = true


Advertisements
Advertisements