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?
if (!new File("D:\\Log\\Sample").exists()) { throw new FileNotFoundException("Yikes!"); }
Besides File.exists()
, there are also File.isDirectory()
and File.isFile()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With