How to Create a Directory in Java? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In Java, creating a directory is a common operation when working with file system manipulation. Directories are used to organize files and other directories into a hierarchical structure. This article will guide you through the process of creating a directory in Java, providing step-by-step examples and explanations. Program to Create Current Directory in Javamkdir() method is available on the File class and attempts to create the specified directory. It only creates the directory itself and throws an exception if any parent directories do not exist. Below is the implementation of Create Current Directory in Java: Java // Java Program to Create Current Directory import java.io.File; // Driver Class public class GFG { // main function public static void main(String[] args) { // Sprecify the Directory Name String directoryName = "My_Learning"; // Address of Current Directory String currentDirectory = System.getProperty("user.dir"); // Specify the path of the directory to be created String directoryPath = currentDirectory + File.separator + directoryName; // Create a File object representing the directory File directory = new File(directoryPath); // Attempt to create the directory boolean directoryCreated = directory.mkdir(); if (directoryCreated) { System.out.println("Directory created successfully at: " + directoryPath); } else { System.out.println("Failed to create directory. It may already exist at: " + directoryPath); } } } Output: The created folder can be seen as follows if we go to that location: Comment More infoAdvertise with us Next Article How to Create a Directory in Java? H heysaiyad Follow Improve Article Tags : Java Java Programs java-file-handling Java-File Class Java-Files Java Examples +2 More Practice Tags : Java Similar Reads How to Watch a Directory for Changes in Java ? In this article, we will learn how to watch the directory changes through the Java programming language. Java provides a robust and efficient way to monitor directories for changes through the java.nio.file package. The WatchService API allows developers to receive notifications about various events 2 min read How to List all Files in a Directory in Java? Java provides a feature to interact with the file system through the java.io.file package. This feature helps developers automate the things to operate with files and directories. In this article, we will learn how to list all the files in a directory in Java. Approaches to list all files in a direc 3 min read How to Create a Package in Java? Package in Java is a mechanism to encapsulate a group of classes, sub-packages, and interfaces. All we need to do is put related classes into packages. After that, we can simply write an import class from existing packages and use it in our program. A package is a container of a group of related cla 4 min read Java Program to Create a File in a Specified Directory Creating a file in a specific directory using Java can be done in various ways. This is done using predefined packages and Classes. In this article, we will learn about how to create a file in a specified directory. Methods to Create a File in a Specified DirectoryThree such methods to create a file 3 min read Java Program to Delete a directory The class named java.io.File represents a file or directory (path names) in the system. This class provides methods to perform various operations on files/directories. The delete() method of the File class deletes the files and empty directory represented by the current File object. If a directory i 2 min read Like