Languages
[Edit]
EN

Java - create directory using mkdir()

0 points
Created by:
Emrys-Li
580

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

Alternative titles

  1. Java - create folder using mkdir()
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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