How to create a directory using Java?

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 12-Jan-2018 06:23:57
Advertisements