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:
xxxxxxxxxx
1
File myDirectory = new File("path/directory_name");
2
3
myDirectory.mkdir();
In this example we create a new folder under the given path using mkdir()
method.
xxxxxxxxxx
1
import java.io.File;
2
3
public class Example {
4
5
public static void main(String[] args) {
6
File newDirectory = new File("C:\projects\example\newFolder");
7
8
if (!newDirectory.exists()) {
9
if (newDirectory.mkdir()) {
10
System.out.println("New directory created succesfully.");
11
} else {
12
System.out.println("Couldn't create directory.");
13
}
14
}
15
}
16
}
17
Result:
