Johnydep
Johnydep

Reputation: 6277

distinguish between file and directory using java

I have rather a very basic question but somehow it is confusing to me. Normally to check the existence of both file and directory we can do so by using boolean file.exists()
However i am wondering, is there any way that one can determine if given path is a directory or a file.

It would be nice if you can provide some short example using java.

Upvotes: 0

Views: 3731

Answers (2)

Gazler
Gazler

Reputation: 84140

You can use isDirectory and isFile.

Upvotes: 3

hvgotcodes
hvgotcodes

Reputation: 120178

Yes, from the documentation, there are the methods isFile and isDirectory

Upvotes: 6

Related Questions