File mkdir() method in Java with examples Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report 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 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.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 // 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 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 mkdir() 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 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 p 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 URL getFile() method in Java with Examples The getFile() function is a part of URL class. The function getFile() returns the file name of a specified URL. The getFile() function returns the path and the query of the URL. Function Signature: public String getFile() Syntax: url.getFile() Parameter: This function does not require any parameter 2 min read File renameTo() method in Java with examples The renameTo() method is a part of File class. The renameTo() function is used to rename the abstract path name of a File to a given path name. The function returns true if the file is renamed else returns false Function Signature: public boolean renameTo(File destination) Syntax: file.renameTo(File 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 Like