Java-Directory-Creator2.txt: Other cited examples: https://jenkov.com/tutorials/java-io/file.html Use of File.Separators: https://www.w3docs.com/snippets/java/when-should-i-use-file-separator-and-when-file-pathseparator.html Use of the assert keyword: https://www.w3docs.com/snippets/java/what-does-the-java-assert-keyword-do-and-when-should-it-be-used.html 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() 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 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.mkdir()) { // 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 mkdir() can create the parent directories of the abstract path name if the directories are not present. // Java program to demonstrate // the use of File.mkdir() 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.mkdir()) { // 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 cannot be created ======================================================== File mkdirs() method in Java with examples 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 does not accept a 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 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 test the function mkdirs() to create the parent directories of the abstract pathname if the directories are not present. // 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 work in an inline IDE.