The
mkdirs() method is a part of
File class. The mkdirs() function is used to create a new directory denoted by the abstract pathname and also all the non existent parent directories of the abstract pathname. If the mkdirs() function fails to create some directory it might have created some of its parent directories. The function returns true if directory is created else returns false.
Function Signature:
public boolean mkdirs()
Syntax:
file.mkdirs()
Parameters: This method do not accepts any parameter.
Return Value: The function returns
boolean data type. The function returns true if directory is created else returns false.
Exception: This method throws
SecurityException if the method does not allow directory to be created
Below programs will illustrate the use of mkdirs() function:
Example 1: Try to create a new directory named program in "f:" drive.
Output:
Directory is created
Example 2: Try to create a new directory named program1 in "f:\program" directory, but program directory is not created. We will test whether the function mkdirs() can create the parent directories of the abstract pathname if the directories are not present.