How to create a new directory in java

This example shows you how to create the directory from java.

You can create the directory from File object by calling the mkdir() method.

Below is the example of creating the directory from java.

package com.java.connect.io;

//How to create a new directory in java
import java.io.File;

public class CreateNewDirectoryExample {
	public static void main(String[] args) {
		// Get the file instance
		File file = new File("test");

		// You can create the directory using
		// mkdir() method of File object as shown below
		boolean created = file.mkdir();
		// If the directed newly it will get as true
		if (created) {
			System.out.println("Created " + file.getAbsolutePath());
		} else {
			// Other wise directory was already exists
			System.out.println("Directory already there");
		}
	}
}