To determine if an abstract pathname is a directory we can use the File.isDirectory()
method. Here is an example code.
package org.kodejava.io;
import java.io.File;
public class IsDirectoryExample {
public static void main(String[] args) {
// Creates a instance of File.
File file = new File("C:/Users/wsaryada");
// Check if the abstract pathname is a directory by calling
// isDirectory() method of the File class.
if (file.isDirectory()) {
System.out.println("This file is a directory.");
} else {
System.out.println("This is just an ordinary file.");
}
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024