Java-Create New Directory

Create New Directory

The mkdir( ) method creates a directory, returning true on success and false on failure. Failure indicates that the path specified in the File object already exists, or that the directory cannot be created because the entire path does not exist yet.

Program

Program Source

import java.io.File;

public class Javaapp {

    public static void main(String[] args) {
        
        File f1 = new File("C:\\java\\hajsof");
        
        if(f1.mkdir())
        {
            System.out.println("Directory Creation : Success");
        }else
        {
            System.out.println("Directory Creation : Unsuccess");
        }
    }
}

Leave a Comment