How to create a directory in Java? How to create a directory in Java? java java

How to create a directory in Java?


new File("/path/directory").mkdirs();

Here "directory" is the name of the directory you want to create/exist.


After ~7 year, I will update it to better approach which is suggested by Bozho.

File theDir = new File("/path/directory");if (!theDir.exists()){    theDir.mkdirs();}


With Java 7, you can use Files.createDirectories().

For instance:

Files.createDirectories(Paths.get("/path/to/directory"));