Create Directory Java Program

In this post we are going to learn a classic example of create directory java program.

To create a directory in java we have mkdir() method in file class. This method in file class returns boolean value.

First we have to import InputOutput package in java.

Second we have to check if directory exists, if no, create one. So, let’s see code implementation,

Example: Create Directory Java Program

Create Directory Java Program

Also Read – Create File Java Program

import java.io.*;

public class Create_Directory {

public static void main(String[] args) {

File directory = new File("C://Directory_Example");

boolean is_Created = directory.mkdir();

if(is_Created){
System.out.println("Directory created");
}
else{
System.out.println("Directory not created");
}
}
}

Output:

Directory created

About the author

admin

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *