Friday 18, Apr 2025
We are moved to new domain
Click -> www.ehowtonow.com
Sunday, 21 May 2017

How to Create Directory using Java File.mkdirs

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.javatutorialcorner.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

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer

Related Posts:

  • How to find the size of directory using FileUtils public static long sizeOfDirectory(File directory) Counts the size of a directory recursively (sum of the length of all files). Note that overflow is not detected, and the return value may be negative if overflow occurs. See… Read More
  • How to check directory or file is hidden using Java boolean java.io.File.isHidden() Tests whether the file named by this abstract pathname is a hidden file. The exact definition of hidden is system-dependent. On UNIX systems, a file is considered to be hidden if its name beg… Read More
  • How to traverse the directories using Java This program explains how to traverse the directories and sub directories using Java DirectoryTraversal.java package com.javatutorialcorner.directory; import java.io.File; public class DirectoryTraversal { public s… Read More
  • How to find parent directory of file using JavaString java.io.File.getParent()Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory. The parent of an abstract pathname consists of the pathname's prefix, i… Read More
  • How to delete directory using Java boolean java.io.File.delete() Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted. Note that the java.nio.file.Fil… Read More
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: How to Create Directory using Java File.mkdirs Rating: 5 Reviewed By: eHowToNow