How to check if File is Directory in Java

We have 2 ways to check if file is Directory in java
1. java.io.File API’s isDirectory() method
2. java.nio.file.Files API’s readAttributes() method.

1. Example : Check If File is Directory Using isDirectory()

Output

2. Example : Check If File is Directory Using readAttributes()

Output

Reference

1. File isDirectory method
1. File readAttributes method

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn