How to create a Directory recursively using Java?

Java 8Object Oriented ProgrammingProgramming

The java.io.File.mkdirs() creates the directory named by this abstract pathname, together with necessary and non-existent parent directories.

Example

Live Demo

import java.io.File;

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

Output

Status = true
raja
Published on 12-Jan-2018 06:36:27
Advertisements