Java – Create directories if they are not in path

November 17, 2020

When you create a file with Java code you may find the directories are not found in the path you specify.

You can use the following code to create missing directories.

String path="//template//components/view";
File directory = new File(path);
 if (! directory.exists()){
     directory.mkdir();
 }