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:
For more information how to create directory in Java please visit oracle site here