Q:

Create a directory in Java

belongs to collection: Java Files & Directories Programs

0

Syntax:

    //file object creation by passing the path 
    File file = new File("d://course");

    //creating directory named "course" in "d://" drive
    file.mkdir();

    Output:
    true

 

All Answers

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

Java code to create a directory

//Java code to create a directory  

import java.io.*;

public class Main {
  public static void main(String[] args) {
    //file object creation by passing the path 
    //where we have to create the directory
    File file = new File("d://course");

    //variable to store the result
    //assigning false as an initial value
    boolean result = false;

    //creating directory named "course" in "d://" drive
    result = file.mkdir();

    if (result == true) {
      System.out.println("Directory created successfully...");
    } else {
      System.out.println("Directory is not created...");
    }
  }
}

Output

Directory created successfully...

 

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

total answers (1)

Create directory along with required nonexistent p... >>
<< Create temporary file in specified directory in Ja...