isDirectory
时间: 2024-01-18 15:05:02 浏览: 104
isDirectory is a boolean method in Java that is used to check whether a specified path refers to a directory or not. The method returns true if the path refers to a directory, and false otherwise. This method is typically used in file handling operations to determine whether a given path represents a file or a directory. Here is an example of how to use the isDirectory method:
```
import java.io.File;
public class Example {
public static void main(String[] args) {
File file = new File("C:/Users/username/Documents");
if (file.isDirectory()) {
System.out.println("The specified path is a directory.");
} else {
System.out.println("The specified path is not a directory.");
}
}
}
```
阅读全文