Q:

Create directory along with required nonexistent parent directories in Java

belongs to collection: Java Files & Directories Programs

0

Package to use: import java.io.*;

Syntax:

    // create File object with directories
    File dirs = new File("C://course//semester1//programming//java");

    //method call to create directories
    dirs.mkdirs();

    Output:
    true

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Java code to create directory along with required nonexistent parent directories

// Java code to create directory along with required 
// nonexistent parent directories

import java.io.*;

public class CreateDIRwithParentDIRs {
  public static void main(String[] args) {
    // create File object with directories
    File dirs = new File("C://course//semester1//programming//java");

    // variable to store result 
    // and method call to create directories
    boolean result = dirs.mkdirs();

    if (result)
      System.out.println("Directories created sucessfully...");
    else
      System.out.println("Error occured...");
  }
}

Output

Directories created sucessfully...

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Comparing the paths of the two files in Java... >>
<< Create a directory in Java...