Create Directory using Java
Different ways to create directory in Java.
Using Files Class
You can use Files.createDirectories to create a directory and parent directories that do not exist.
1 | Path path = Paths.get("output/newpath/"); |
Using File Class
java.io.File class provides mkdir()
and mkdirs()
method to create directory. mkdir()
only create a directory. mkdirs()
creates directory and all necessary but nonexistent parent directories. Both return true if directory is created.
1 | File file = new File("output/newpath/"); |