EN
Java - create directory using mkdir()
0
points
In this article, we would like to show you how to create directory / folder using mkdir()
method in Java.
Quick solution:
File myDirectory = new File("path/directory_name");
myDirectory.mkdir();
Practical example
In this example we create a new folder under the given path using mkdir()
method.
import java.io.File;
public class Example {
public static void main(String[] args) {
File newDirectory = new File("C:\projects\example\newFolder");
if (!newDirectory.exists()) {
if (newDirectory.mkdir()) {
System.out.println("New directory created succesfully.");
} else {
System.out.println("Couldn't create directory.");
}
}
}
}
Result: