How to create a directory using Java?



You can create a directory in the specified path using the mkdir() method of the File class. This method returns true is a directory created.

Example

import java.io.File;
public class CreateDirectory {
   public static void main(String args[]) {
      String dir ="C:/Users/Tutorialspoint/Desktop/movies/sampledirectory";
      File directory = new File(dir);
      System.out.println(directory.mkdir());
   }
}

Output

true
Sai Subramanyam
Sai Subramanyam

Passionate, Curious and Enthusiastic.


Advertisements