How to create a folder in Java?

How can I create an empty folder in Java?


File f = new File("C:\\TEST");
try{
    if(f.mkdir()) { 
        System.out.println("Directory Created");
    } else {
        System.out.println("Directory is not created");
    }
} catch(Exception e){
    e.printStackTrace();
} 

Call File.mkdir, like this:

new File(path).mkdir();

With Java 7 and newer you can use the static Files.createDirectory() method of the java.nio.file.Files class along with Paths.get.

Files.createDirectory(Paths.get("/path/to/folder"));

The method Files.createDirectories() also creates parent directories if these do not exist.


Use mkdir():

new File('/path/to/folder').mkdir();

Use the mkdir method on the File class:

https://docs.oracle.com/javase/1.5.0/docs/api/java/io/File.html#mkdir%28%29