Create directory along with required nonexistent parent directories - Java File Path IO

Java examples for File Path IO:Directory Create

Description

Create directory along with required nonexistent parent directories

Demo Code


import java.io.*;
 
public class Main {
 
  public static void main(String[] args) {
   //from  w w w.jav  a2 s . c  om
     File dir = new File("C://Folder//Parent1//Parent2//DemoDir");
     boolean isDirCreated = dir.mkdirs();
   
     if(isDirCreated)
       System.out.println("Directory created along with required nonexistent parent directories");
     else
       System.out.println("Failed to create directory");
  }
}

Result


Related Tutorials