In this tutorial, I am writing simple program about How to create directory in Java.

The new directory can be created using Java with help of mkdir() method. Which is part of java.io.File class. If the directory is created successfully it will return true. It will return false if the directory is already available. The example program were attached in the post.

CreatingDirectoryExample.java

package com.dineshkrish.files;
import java.io.File;
/**
* 
* @author Dinesh Krishnan
*
*/
public class CreatingDirectoryExample {
public static void main(String[] args) {
// Parent Path
String path = "C:\\Users\\dineshkrishnan\\";
// Directory Name
String directoryName = "myImage";
File file = new File(path + directoryName);
// Creating the directory in specified parent path
boolean creationStatus = file.mkdir();
if(creationStatus) {
System.out.println("Directory is Created");
} else {
System.out.println("Directory is Not Created");
}
}
}

References

1. Java API Documentation

Tags:

No responses yet

Leave a Reply

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