File mkdirs() method in Java with examples Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report 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. Java // Java program to demonstrate // the use of File.mkdirs() method import java.io.*; public class GFG { public static void main(String args[]) { // create an abstract pathname (File object) File f = new File("F:\\program"); // check if the directory can be created // using the abstract path name if (f.mkdirs()) { // display that the directory is created // as the function returned true System.out.println("Directory is created"); } else { // display that the directory cannot be created // as the function returned false System.out.println("Directory cannot be created"); } } } 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. Java // Java program to demonstrate // the use of File.mkdirs() method import java.io.*; public class GFG { public static void main(String args[]) { // create an abstract pathname (File object) File f = new File("F:\\program\\program1"); // check if the directory can be created // using the abstract path name if (f.mkdirs()) { // display that the directory is created // as the function returned true System.out.println("Directory is created"); } else { // display that the directory cannot be created // as the function returned false System.out.println("Directory cannot be created"); } } } Output: Directory is created The programs might not run in an online IDE. please use an offline IDE and set the path of the file Comment More infoAdvertise with us Next Article File mkdirs() method in Java with examples A andrew1234 Follow Improve Article Tags : Java Java-Functions Java-IO package Java-File Class Practice Tags : Java Similar Reads File mkdir() method in Java with examples The mkdir() method is a part of File class. The mkdir() function is used to create a new directory denoted by the abstract pathname. The function returns true if directory is created else returns false. Function Signature: public boolean mkdir() Syntax: file.mkdir() Parameters: This method do not ac 2 min read Files size() method in Java with Examples size() method of java.nio.file.Files help us to get the size of a file (in bytes). This method returns the file size, in bytes by taking the path of the file as a parameter. The size may differ from the actual size on the file system due to compression, support for sparse files, or other reasons. Th 2 min read FileStore name() method in Java with Examples The name() method of a FileStore class is used to return the name of this file store as a String. The format of the name is typically the name of the storage pool or volume. The string returned by this method may differ from the string returned by the toString() method. Syntax: public abstract Strin 2 min read Files copy() Method in Java with Examples The copy() method of java.nio.file.Files Class is used to copy bytes from a file to I/O streams or from I/O streams to a file. I/O Stream means an input source or output destination representing different types of sources e.g. disk files. Methods: Based on the type of arguments passed, the Files cla 5 min read File isFile() method in Java with Examples The isFile() function is a part of File class in Java. This function determines whether the is a file or Directory denoted by the abstract filename is File or not. The function returns true if the abstract file path is File else returns false. Function signature: public boolean isFile() Syntax: file 2 min read Like