file.mkdirs
时间: 2024-06-01 10:11:37 浏览: 59
()The method mkdirs() is a built-in method in Java that creates a directory and all its parent directories if they do not exist. The method returns a boolean value that indicates whether the directory was successfully created or not.
Syntax:
public boolean mkdirs()
Example:
File file = new File("C:/Users/Test/Desktop/MyFolder");
boolean success = file.mkdirs();
if (success) {
System.out.println("Directory created successfully");
} else {
System.out.println("Failed to create directory");
}
In this example, the mkdirs() method is used to create a directory called "MyFolder" on the desktop of the user "Test". The method returns true if the directory was successfully created, and false otherwise. The boolean value is stored in the variable "success", and a message is printed to the console indicating whether the directory was created successfully or not.
阅读全文