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

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

Answer from Bozho on Stack Overflow
🌐
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. mkdir() method is available on the File class and attempts to create the specified directory.
🌐
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.
🌐
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.
🌐
ZetCode
zetcode.com › java › createdirectory
Java create directory - learn how to create a directory in Java
The Files.createDirectories creates a new directory; if the parent directories do not exist, they are created as well. The method does not thrown an exception if the directory already exist. ... package com.zetcode; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; ...
🌐
Blogger
java-demos.blogspot.com › 2012 › 10 › create-directory-in-java.html
How to create folder in Java — Java Demos
A tiny and easy example to create a directories in Java with mkdir() and mkdirs() methods. import java.io.File; class CreateDirectory { public static void main(String args[]) { // Create a java.io.File object, specify the name of the folder File f=new File("mydir"); // Create directory with ...
🌐
Alvin Alexander
alvinalexander.com › java › java-create-directory-directories-file-mkdirs
How to create directories in Java | alvinalexander.com
If you need to create multiple directories at one time, you can use the mkdirs method of the Java File class, as shown in this example:
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › io › dirs.html
Creating and Reading Directories (The Java™ Tutorials > Essential Java Classes > Basic I/O)
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 directory.
🌐
Medium
medium.com › @AlexanderObregon › javas-files-createdirectories-method-explained-cb824678b0b7
Java’s Files.createDirectories() Method Explained | Medium
January 26, 2025 - The createDirectories() method can be used in various scenarios where directory creation is needed, from simple use cases to more complex setups. Below are some examples to help you understand how this method works and how it can be applied.
🌐
Mccue
javabook.mccue.dev › files › creating_a_folder
Create a Folder - Modern Java
To create a folder, you can use Files.createDirectory. import java.nio.file.Files; import java.nio.file.Path; class Main { void main() throws IOExeption { Path folderPath = Path.of("example1"); Files.createDirectory(folderPath); } } This, like the other methods in Files, might throw an IOException.
🌐
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.
🌐
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
Enter file name to be created Abhishek.txt File already exists Don't forget to close Scanner once done, a good practice to prevent resource leaks in Java. Alternatively, you can also use try-with-resources statements from Java 7, which facilitate automatic resource clean-up for you. That not only take care of releasing resources once you are done with that, but also removes coding headache and finally block from above code, making it more concise and readable. That's all about how to create or make files and directories in Java.
🌐
TutorialsPoint
tutorialspoint.com › how-to-create-a-directory-in-project-folder-using-java
How to create a directory in project folder using Java?
import java.io.File; import java.util.Scanner; public class CreateDirectory { public static void main(String args[]) { System.out.println("Enter the path to create a directory: "); Scanner sc = new Scanner(System.in); String path = sc.next(); System.out.println("Enter the name of the desired a directory: "); path = path+sc.next(); //Creating a File object File file = new File(path); //Creating the directory boolean bool = file.mkdir(); if(bool){ System.out.println("Directory created successfully"); } else { System.out.println("Sorry couldn’t create specified directory"); } } }
🌐
Attacomsian
attacomsian.com › blog › java-create-directory
How to create a directory in Java
December 13, 2019 - You can even use Files.createDirectories() to create multiple nested directories at once. This method creates all nonexistent parent directories first. Here is an example: try { // directory path Path path = Paths.get("./java/jvm/1.8"); // create directory Files.createDirectories(path); }catch (IOException ex) { ex.printStackTrace(); } You can also use the classic Java I/O package (classes in java.io.*) to create a new directory.
🌐
How to do in Java
howtodoinjava.com › home › i/o › creating new directories in java
Creating New Directories in Java
April 21, 2022 - We will learn to create the archive directory in such a way: ... The createDirectory() creates the new directory if all the parent directories exist. The check for the existence of the file and the creation of the directory if it does not exist ...
🌐
OpenGenus
iq.opengenus.org › creating-and-deleting-folders-in-java
Creating and Deleting Folders in Java
February 7, 2020 - File Java class of java.io package represents a file or directory in the system. It contains various methods to perform operations on file/ directory. mkdir() method of file class is used to create a new directory denoted by the abstract pathname.
🌐
O'Reilly
oreilly.com › library › view › java-cookbook › 0596001703 › ch10s10.html
Making New Directories - Java Cookbook [Book]
June 21, 2001 - Making New DirectoriesProblemYou need to create a directory. SolutionUse java.io.File’s mkdir( ) or mkdirs( ) method. DiscussionOf the two methods used for creating directories,... - Selection from Java Cookbook [Book]
Author   Ian F. Darwin
Published   2001
Pages   888
🌐
TutorialsPoint
tutorialspoint.com › how-to-create-a-directory-hierarchy-using-java
How to create a directory hierarchy using Java?
March 12, 2024 - To create a hierarchy of new directories you can using the method mkdirs() of the same class. This method creates the directory with the path represented by the current object, including non-existing parent directories. import java.io.File; import java.util.Scanner; public class CreateDirectory ...