To check if a path is a file or folder in Java you can use the following snippet.

Sample Java

File path = new File("File or DirectoryName");  

boolean isDir = path.isDirectory();  
if (isDir) {  
    // its a directory  
} else {  
    // its a file 
}  

One thought on “How to check if a path is a file or folder in Java”

Leave a Reply