Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Check Path is existing or not in java?

Tags:

I have a java program which take path as argument. I want to check whether given path is existing or not before doing other validation. Eg: If i give a path D:\Log\Sample which is not not exist, it has to throw filenotfound exception. How can i do that?

like image 599
raja Avatar asked Jan 28 '09 10:01

raja


1 Answers

if (!new File("D:\\Log\\Sample").exists()) {    throw new FileNotFoundException("Yikes!"); } 

Besides File.exists(), there are also File.isDirectory() and File.isFile().

like image 64
Zach Scrivena Avatar answered Sep 29 '22 13:09

Zach Scrivena