Determine if it is a File or Directory in Java
Description
The following code shows how to determine if it is a File or Directory.
Example
//from w ww. j a v a 2s . com
import java.io.File;
public class Main {
public static void main(String[] args) {
File file = new File("C:/FileIO");
boolean isFile = file.isFile();
if (isFile){
System.out.println("a file.");
}else{
System.out.println("not a file.");
}
boolean isDirectory = file.isDirectory();
if (isDirectory){
System.out.println("a directory.");
}else{
System.out.println("not a directory.");
}
}
}
The code above generates the following result.