How to create empty folder in java?

JavaCreatefileCreate Directory

Java Problem Overview


I tried to use the File class to create an empty file in a directory like "C:/Temp/Emptyfile". However, when I do that, it shows me an error : "already made folder Temp". Otherwise, it won't create one for me.

So, how do I literally create folders with java API?

Java Solutions


Solution 1 - Java

Looks file you use the .mkdirs() method on a File object: http://www.roseindia.net/java/beginners/java-create-directory.shtml

// Create a directory; all non-existent ancestor directories are
// automatically created
success = (new File("../potentially/long/pathname/without/all/dirs")).mkdirs();
if (!success) {
    // Directory creation failed
}

Solution 2 - Java

You can create folder using the following Java code:

File dir = new File("nameoffolder");
dir.mkdir();

By executing above you will have folder 'nameoffolder' in current folder.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser385261View Question on Stackoverflow
Solution 1 - JavasarnoldView Answer on Stackoverflow
Solution 2 - JavaajdukeView Answer on Stackoverflow