new File("/path/directory").mkdirs();

Here "directory" is the name of the directory you want to create/exist.

Answer from Bozho on Stack Overflow
🌐
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.
Discussions

what's with a Java project folder structure ?

It depends on the build system in use for the project.

In the days of Ant or if you let the IDE set it up for you without specifying a build, it was mostly:

src/
bin/

Maven and Gradle use the Maven Standard Directory Layout ( https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html )

src
  main
    {lang}
      packages
    resources
  test
    {lang}
      packages
    resources

You can see that when using Gradle for groovy - https://docs.gradle.org/current/userguide/groovy_plugin.html#sec:groovy_project_layout the lang for the groovy sources is 'groovy'. This is important if you mix groovy, scala, kotlin, and java all in one project. For example (not my project, just one I found out there) https://github.com/bellingard/sample_multi-language-project

More on reddit.com
🌐 r/javahelp
9
8
September 22, 2018
Create directory in Javascript
In regular macro programming, you can create a directory with File.makeDirectory; http://imagej.net/developer/macro/functions.html#F I tried in Javascript importPackage(Packages.ij.File); File.makeDirectory("a"); But I get Error: Java class "java.io.File" has no public instance field or method ... More on forum.image.sc
🌐 forum.image.sc
7
0
December 11, 2015
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › io › dirs.html
Creating and Reading Directories (The Java™ Tutorials > Essential Java Classes > Basic I/O)
If you don't specify any FileAttributes, the new directory will have default attributes. For example: ... The following code snippet creates a new directory on a POSIX file system that has specific permissions:
🌐
Medium
medium.com › @AlexanderObregon › javas-files-createdirectories-method-explained-cb824678b0b7
Java’s Files.createDirectories() Method Explained | Medium
January 26, 2025 - This eliminates the need to manually create each parent directory step by step. Again, the IOException is handled to catch issues that might occur during the operation. If the path contains invalid characters, the method will throw an exception. Here’s how to handle this situation: import java.nio.file.*; public class InvalidPathExample { public static void main(String[] args) { try { Path path = Paths.get("invalid_path::/logs"); Files.createDirectories(path); System.out.println("Directories created: " + path); } catch (IOException e) { System.err.println("Failed to create directories: " + e.getMessage()); } } }
🌐
Coderanch
coderanch.com › t › 708245 › java › Creating-directory-doesn-exist-writing
Creating a directory if it doesn't exist and then writing a file (I/O and Streams forum at Coderanch)
April 2, 2019 - If you create a File object for the directory you want to create you can use the isDirectory() and exists() methods to determine if a directory (or file) with that name already exists and if it doesn't use the mkDir() or mkDirs() method to create the directory.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-create-a-directory-in-java
How to Create a Directory in Java? - GeeksforGeeks
July 23, 2025 - This article will guide you through the process of creating a directory in Java, providing step-by-step examples and explanations.
Find elsewhere
🌐
GitHub
gist.github.com › barbietunnie › a9b63e58d806859bba816862b8f101b3
Create recursive directory using Java NIO · GitHub
Create recursive directory using Java NIO. GitHub Gist: instantly share code, notes, and snippets.
🌐
O'Reilly
oreilly.com › library › view › java-cookbook › 0596001703 › ch10s10.html
Making New Directories - Java Cookbook [Book]
June 21, 2001 - Use java.io.File’s mkdir( ) or mkdirs( ) method. Of the two methods used for creating directories, mkdir( ) creates just one directory while mkdirs( ) creates any parent directories that are needed.
Author   Ian F. Darwin
Published   2001
Pages   888
🌐
Jenkov
jenkov.com › tutorials › java-io › file.html
Java File
December 17, 2019 - Provided that the C drive exists, this example will create all the directories in the path c:\users\jakobjenkov\newdir. The mkdirs() method will return true if all the directories were created, and false if not. The Java File class enables you to read the length in bytes of a file.
🌐
Reddit
reddit.com › r/javahelp › what's with a java project folder structure ?
r/javahelp on Reddit: what's with a Java project folder structure ?
September 22, 2018 -

So here the thing guys. I'm a data engineer by profession meaning ETL/SQL master. Recently with the explosion of new tools that hit the market in big data, I'm trying to learn Java. The challenge is, wrapping my head around Java folder structure. When I look at code in GitHub for few of the Apache projects like spark/airflow, it's so convoluted and varies by developer. Is there a rule or strategy that's developers commonly follow?

🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › file › Files.html
Files (Java Platform SE 8 )
April 21, 2026 - On some file systems this is known as creating a "hard link". Whether the file attributes are maintained for the file or for each directory entry is file system specific and therefore not specified. Typically, a file system requires that all links (directory entries) for a file be on the same file system. Furthermore, on some platforms, the Java ...
🌐
How to do in Java
howtodoinjava.com › home › i/o › creating new directories in java
Creating New Directories in Java
April 21, 2022 - Learn to create a new single directory or nested directory along with parent directories in a specified path using Java IO and NIO classes.
🌐
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.
🌐
Coderanch
coderanch.com › t › 496804 › java › creating-directory
creating directory (Beginning Java forum at Coderanch)
May 25, 2010 - Thomas Young wrote:This will create a directory named "test" in the location that the JAR is ran from. True, but keep in mind that this is not necessarily the location where the JAR is located. With -jar or -cp / -classpath you can run classes from your JAR file from basically anywhere.
🌐
TutorialsPoint
tutorialspoint.com › how-to-create-a-new-directory-by-using-file-object-in-java
How to create a file in a specified directory using Java
August 1, 2019 - This example demonstrates how to create a file in a specified directory using File.createTempFile() method of File class. import java.io.File; public class Main { public static void main(String[] args) throws Exception { File file = null; File ...
🌐
JetBrains
youtrack.jetbrains.com › articles › SUPPORT-A-345 › How-to-create-a-regular-directory-not-a-package-in-a-Java-project-in-IntelliJ-IDEA
How to create a regular directory (not a package) in a Java project in IntelliJ IDEA | Knowledge Base
Create a regular folder in a directory that is not marked as sources root or a package (solid grey) Right-click on the blue folder or a package -> Open in -> Explorer, then create a new folder in the system manually, and switch back to the IDE
🌐
Alvin Alexander
alvinalexander.com › java › java-create-directory-directories-file-mkdirs
How to create directories in Java | alvinalexander.com
(Also written as, “How do I make a directory in Java?”) To create a directory in Java, just use these two methods from the Java File class:
🌐
Quora
quora.com › How-do-I-create-a-new-folder-on-a-desktop-using-Java
How to create a new folder on a desktop using Java - Quora
Answer: A basic approach is this: [code]/** This does not work as it should, don't do this. */ public void makeFolder(String folderName) { String homeFolder = System.getProperty("user.home"); Paths.get(homeFolder, "Desktop", folderName).toFile().mkdir(); } [/code]And it seems reasonable....
🌐
Image.sc
forum.image.sc › development
Create directory in Javascript - Development - Image.sc Forum
December 11, 2015 - In regular macro programming, you can create a directory with File.makeDirectory; http://imagej.net/developer/macro/functions.html#F I tried in Javascript importPackage(Packages.ij.File); File.makeDirectory("a"); But I get Error: Java class ...