Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)
reshown by

How do I create a Directory/folder?

Once I have tested System.getProperty("user.home");

I have to create a directory (directory name "new folder" ) if and only if a new folder does not exist.

1 Answer

0 votes
by (119k points)
reshown by

Here are the two methods to create a directory in Java:

Method 1:

new File("/path/directory").mkdirs();

In this, "directory" represents the name of the directory you want to create/exist.

Method 2:

You can use FileUtils.forceMkdir

FileUtils.forceMkdir("/path/directory");

If you want to learn Java, you can register for this Java Course by Intellipaat.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...