JavaHow to Create a New Directory Folder in Java

How to Create a New Directory Folder in Java

In this quick Java tutorial, we are going to showcase how to create a new directory folder using Java. We will be relying on the Files.createDirectory method to create our directory folder. Feel free to copy the code below into your Integrated Development Environment (IDE) or code editor to follow along:


import java.nio.file.*;

public class CreateDirectory
	public static void main(String args[])
		CreateDirectory createDirectory = new CreateDirectory();
	private void proceed()
		final String NEW_DIR_NAME = "newDir";
			System.out.println("Folder " + NEW_DIR_NAME + " created.");
		catch(IOException e)


This Java code results in the following output when you run it in your development environment:

[root@mypc]# java CreateDirectory
Folder newDir created.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories