Create Directory Java

Create Directory Java

In below sample java program you will see how to create directory/folder. We will create directory if its not exists and exists simply output message on the console directory already exists:

Sample Java Program:

package com.javahonk;

import java.io.File;

public class CreateDirectoryJava {

	public static void main(String[] args) {
		
		File crateDirectory = new File("C:\\JavaHonk\\CreateDirectory");
		
		if (crateDirectory.exists()) {
			System.out.println("Directory Folder already exists");
		} else {
			Boolean dirCreated = crateDirectory.mkdir();
			if (dirCreated) {
				System.out.println("Directory created with name: "+crateDirectory.getName());
				System.out.println("Absolute path: "+crateDirectory.getAbsolutePath());
			}
		}		

	}

}

Output:

Create Directory Java

For more information how to create directory in Java please visit oracle site here

Leave a Reply

Your email address will not be published. Required fields are marked *