You can use File.mkdir() or File.mkdirs() to create a directory. Between the two, the latter method is more tolerant and will create all intermediate directories as needed. Also, since I see that you use "\\" in your question, I would suggest using File.separator for a portable path separator string.

Answer from Michael Aaron Safyan on Stack Overflow
🌐
YouTube
youtube.com › watch
How to create directory and subdirectory structure in java? - YouTube
#learnwithkrishnasandeep #javacodinginterviewquestions #javaexamples #javaprograms #javatutorials #javaprogramming create directory and subdirectory java,c...
Published   December 17, 2015
🌐
Dirask
dirask.com › posts › Java-create-multiple-subfolders-1XoW0j
Java - create multiple subfolders
To do so we use mkdir() method inside the for loop. import java.io.File; public class Example { public static void main(String[] args) { String myDirectoryPath = "C:\\projects\\example\\newFolder"; for (int i = 0; i < 5; i++) { File myDirectory ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-create-directories-recursively
Java Program to Create Directories Recursively - GeeksforGeeks
July 23, 2025 - If the Directory is not present, open a try-catch block, and create a new directory using createDirectories() method. Else, display that the Directory already exists. ... Below is the implementation of the above program.
🌐
Mkyong
mkyong.com › home › java › how to create directory in java
How to create directory in Java - Mkyong.com
July 29, 2020 - In Java, we can use the NIO `Files.createDirectories` to create a directory including all nonexistent parent directories.
Find elsewhere
🌐
Java67
java67.com › 2014 › 02 › how-to-create-file-and-directory-in-java.html
How to Create File and Directory in Java with Example | Java67
1. The code File directory = new File(dir); if (directory.exists()) { ... } doesn't check directory is directory. So here: File directory = new File(dir); if (directory.exists() && directory.isDirectory()) { ...
🌐
Connect
hub.alfresco.com › t5 › alfresco-content-services-forum › how-to-create-directory-structure-using-java-api › td-p › 303037
Solved: How to create directory structure using Java API? - Hyland Connect - 103537
November 9, 2020 - String folderPathQuery = getFolderPathQuery(rootFolderName, siteShortName); //Change the query accordingly if not using sites List<NodeRef> selectedNodes = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), folderPathQuery, null, namespaceService, false); ...
🌐
Baeldung
baeldung.com › home › java › java io › create a directory in java
Create a Directory in Java | Baeldung
January 8, 2026 - In this article, we’ve seen two methods allowing us to create directories in Java. The first one, mkdir(), targets the creation of a single directory, provided its parents already exist. The second one, mkdirs(), is able to create a directory as well as its unexisting parents. The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
🌐
Box Support
support.box.com › hc › en-us › community › posts › 360049196313-Creating-the-folder-and-sub-folders-programmatically
Creating the folder and sub folders programmatically – Box Support
September 3, 2020 - Please see the Box Java SDK documentation — this has information on how to work with folders, including how to create new folders. ... I tried that way by creating statically and hard coded the folder name it worked but if we get the parent folder name and its child folder names dynamically it is giving null pointer exception.
🌐
Connect
hub.alfresco.com › t5 › alfresco-content-services-forum › i-want-to-create-folder-next-inside-folder-need-to-create › td-p › 308199
I want to create folder next inside folder need to create subfolders.
July 26, 2021 - The id can be either one of the constants -root-, -shared-, -my- or an Alfresco Node Identifier (e.g. 444be4a6-5693-4d10-af4b-b55448fe4f97). The POST data defines the folder metadata and looks like in this example:
🌐
TutorialsPoint
tutorialspoint.com › javaexamples › dir_create.htm
How to create directories recursively in Java
import java.io.File; public class Main { public static void main(String[] args) { String directories = "D:\\a\\b\\c\\d\\e\\f\\g\\h\\i"; File file = new File(directories); boolean result = file.mkdirs(); System.out.println("Status = " + result); ...
🌐
Coderanch
coderanch.com › t › 276870 › java › create-directory-subdirectory-files
How to create directory and subdirectory with files. (I/O and Streams forum at Coderanch)
one folder contains sample.txt d:\source\one\sample.txt and two folder,contains two files and sub folder (three). d:\source\two\sample1.txt d:\source\two\sample2.txt d:\source\two\three Three sub folder,contains one gif files d:\source\two\three\samples.gif I need these folder sturcture and store like e:\target\source ... You can create directories using java.io.File.
🌐
Javatpoint
javatpoint.com › how-to-create-a-new-folder-in-java
How to Create a New Folder in Java - Javatpoint
How to Create a New Folder in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › io › dirs.html
Creating and Reading Directories (The Java™ Tutorials > Essential Java Classes > Basic I/O)
You can create a temporary directory using one of createTempDirectory methods: createTempDirectory(Path, String, FileAttribute<?>...) ... The first method allows the code to specify a location for the temporary directory and the second method creates a new directory in the default temporary-file ...
Top answer
1 of 2
1

This is sample program to make directories in java. You can take it as reference and make program to create directories with name current year, current month, current day.

  • First take current date using java.util.Date
  • Then perform some string operation in date to get names of directories.
  • And do some changes in this code as per your need.

    // shows how to create multiple directories in java
    // (multiple directory levels)
    public class JavaCreateMultipleDirectoriesExample
    {
      public static void main(String[] args)
      {
        // the folders "000/111/222" don't exist initially
        File dir = new File("/Users/al/tmp/000/111/222");
    
        // create multiple directories at one time
        boolean successful = dir.mkdirs();
        if (successful)
        {
          // created the directories successfully
          System.out.println("directories were created successfully");
        }
        else
        {
          // something failed trying to create the directories
          System.out.println("failed trying to create the directories");
        }
      }
    }
    
2 of 2
0

I made it by making different directories each time.

String pathname1 = "C:";
String db = "db";
pathname1 += find2 + "/" + db;
System.out.println(pathname1);
File directory1 = new File(pathname1);
if (!directory1.exists()) {
    directory1.mkdirs();
}
String pathname2 = "C:";
String ocr = "ocr";
pathname2 += find2 + "/" + ocr;
System.out.println(pathname2);
File directory2 = new File(pathname2);
if (!directory2.exists()) {
    directory2.mkdirs();
}
String pathname3 = "C:";
String output = "output";
pathname3 += find2 + "/" + output;
System.out.println(pathname3);
File directory3 = new File(pathname3);
if (!directory3.exists()) {
    directory3.mkdirs();
}
String pathname4 = "C:";
String scans = "scans";
pathname4 += find2 + "/" + scans;
System.out.println(pathname4);
File directory4 = new File(pathname4);
if (!directory4.exists()) {
    directory4.mkdirs();
}
🌐
CodingTechRoom
codingtechroom.com › question › create-file-with-subfolders-java
How to Create a File with Subfolders from a Given Path in Java? - CodingTechRoom
Java does not automatically create missing directories when creating a file. Use `Files.createDirectories()` to create the necessary folders before creating the file. Check and create the parent directories of the file as needed.