How to create empty folder in java? [duplicate]

2019-01-21 04:39发布

Possible Duplicate:
How to create a folder?

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?

2条回答
一夜七次
2楼-- · 2019-01-21 04:55

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
}
查看更多
霸刀☆藐视天下
3楼-- · 2019-01-21 05:08

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.

查看更多
登录 后发表回答