Java.io.File.mkdirs() Method
Advertisements
Description
The java.io.File.mkdirs() creates the directory named by this abstract pathname, including necessary and non-existent parent directories.
Declaration
Following is the declaration for java.io.File.mkdirs() method:
public boolean mkdirs()
Parameters
NA
Return Value
The method returns true if the directories was created, with all necessary parent directories; else false.
Exception
SecurityException - If a security manager exists and its methods denies access to create the named directory.
Example
The following example shows the usage of java.io.File.mkdirs() method.
package com.tutorialspoint;
import java.io.File;
public class FileDemo {
public static void main(String[] args) {
File f = null;
boolean bool = false;
try{
// returns pathnames for files and directory
f = new File("C:/Texts/TutorialsPoint/Java");
// create directories
bool = f.mkdirs();
// print
System.out.print("Directory created? "+bool);
}catch(Exception e){
// if any error occurs
e.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result:
Directory created? true