Question

I know how to create a new folder, but i don't know how to way to create an another new folder into a new folder i just created

String y="C:/TEMP/Four Area";
File file=new File(y);
if(file.mkdir()){
    System.out.println("file is created");
}else{
    System.out.println("file is created");
}

But what i want is "C://TEMP/Four Area/New Area", i want system to create "New Area" folder into "Four Area" folder in above code. I tried to use String y="C://TEMP/Four Area/New Area, it won't create any folder

Was it helpful?

Solution

use file.mkdirs() instead to create multiple nested directories

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top