Create a directory (or several directories)

This example shows how to create a directory on disk.
It also shows how to create a hierarchy of directories in case the ancestor(s) of a directory doesn’t exist.
So in the example below we try to create a folder called temp3 which is in temp2 which is in temp1 etc.

On disk we only have c:\temp created before the code is run, so the output from the code above is:

So the mkdirs call will create temp1, temp2 and temp3.
Now, with the folders created we run the code again. This time it will fail to create the folders since they’re already there and the output will be:

Search for more Java info on this site here:
Custom Search

Please type any questions here.