Java File mkdirs() Method
Example
Create a folder inside a new parent folder:
import java.io.File;
public class Main {
public static void main(String[] args) {
File myFolders = new File("parentFolder/childFolder");
myFolders.mkdirs();
File parent = new File("parentFolder");
System.out.println(parent.isDirectory());
System.out.println(myFolders.isDirectory());
}
}
Definition and Usage
The mkdirs() method creates a directory (folder), and all parent folders in the path that do not exist yet.
For example, the path parentFolder/childFolder creates both parentFolder and childFolder.
Tip: Use the mkdir() method to create only one folder.
Syntax
public boolean mkdirs()
Parameter Values
None.
Technical Details
| Returns: | true if the directory was created, together with all missing parent directories, otherwise false (for example, if it already exists). |
|---|
Related Pages
❮ File Methods