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 temp file using Java
  2. How to change File Last modified Date using Java
  3. How to retrieve all the files from Directory using Java File.listFiles()
  4. How to Create Folder using Java File.mkdirs()
  5. How to check file existence in Java
  6. How to compare two file paths using Java
  7. How to retrieve drive/root directories from system using Java
  8. Read File From Class Path or Resource Folder in Java
  9. How to retrieve all the directory names from Directory using Java
  10. How to traverse the directories using Java
  11. How to retrieve present working directory using Java
  12. How to check hidden file or directory using Java
  13. How to read all the files from folder using File.list() in Java
  14. How to delete directory using Java
  15. How to append content into existing file in Java

Be the first to comment

Leave a Reply

Your email address will not be published.


*