Create a Directory in Java

You are currently viewing Create a Directory in Java

Create a directory in Java

//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...

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply