Java File mkdir() Method
Example
Create a folder, then try to create it again:
import java.io.File;
public class Main {
public static void main(String[] args) {
File myFolder = new File("newFolder");
myFolder.delete(); // Delete the folder if it already exists
System.out.println(myFolder.mkdir());
System.out.println(myFolder.mkdir());
}
}
Definition and Usage
The mkdir() method creates a new directory (folder).
It creates only one folder. If a parent folder in the path does not exist, it fails and returns false. Use the mkdirs() method to create the missing parent folders too.
Syntax
public boolean mkdir()
Parameter Values
None.
Technical Details
| Returns: | true if the directory was created, otherwise false (for example, if it already exists). |
|---|
Related Pages
❮ File Methods