How to Create Folder using Java File.mkdirs()

In this tutorial we are going to see about how to create Folder using Java File.mkdirs() example.

boolean java.io.File.mkdirs()

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.

Returns:

true if and only if the directory was created, along with all necessary parent directories; false otherwise

Throws:

SecurityException – If a security manager exists and its java.lang.SecurityManager.checkRead(java.lang.String) method does not permit verification of the existence of the named directory and all necessary parent directories; or if the java.lang.SecurityManager.checkWrite(java.lang.String) method does not permit the named directory and all necessary parent directories to be created

CreateDirectories.java

package com.ehowtonow.regex;

import java.io.File;

public class CreateDirectories {

 public static void createDirectory(){
   String directories = "C:\\JTC\\Java\\Examples\\Directory\\File";
      File file = new File(directories);
      boolean status = file.mkdirs();
      System.out.println("Directory Created : " + status);
 }
 
 public static void main(String args[]){
  createDirectory();
 }
}

Output :
Directory Created : true


Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. How to Create Folder using Java File.mkdirs()
  2. How to append content into existing file in Java
  3. How to retrieve all the files from Directory using Java File.listFiles()
  4. How to get File Last modified Date in Java
  5. How to get file size using Java
  6. How to retrieve present working directory using Java
  7. How to delete directory using Java
  8. How to rename the file using Java
  9. How to retrieve drive/root directories from system using Java
  10. How to delete file using Java
  11. How to check file existence in Java
  12. How to check hidden file or directory using Java
  13. How to change File Last modified Date using Java
  14. Read File From Class Path or Resource Folder in Java
  15. How to retrieve all the directory names from Directory using Java

Be the first to comment

Leave a Reply