Languages
[Edit]
EN

Java - create directory using mkdir()

0 points
Created by:
Dirask Community
6300

In this article, we would like to show you how to create directory / folder using mkdir() method in Java.

Quick solution:

File myDirectory = new File("path/directory_name");

myDirectory.mkdir();

 

Practical example

In this example we create a new folder under the given path using mkdir() method.

import java.io.File;

public class Example {

    public static void main(String[] args) {
        File newDirectory = new File("C:\projects\example\newFolder");

        if (!newDirectory.exists()) {
            if (newDirectory.mkdir()) {
                System.out.println("New directory created succesfully.");
            } else {
                System.out.println("Couldn't create directory.");
            }
        }
    }
}

Result:

Java - create directory using mkdir() example
Java - create directory using mkdir() example

Java - file operations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join