如何检查路径是否存在或不在Java? [英] How to Check Path is existing or not in java?
本文介绍了如何检查路径是否存在或不在Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
if(!new File(D:\\ ())
{
throw new FileNotFoundException(Yikes!);
}
除 File.exists()
,也是 文件.isDirectory()
和 File.isFile()
。
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()
.
这篇关于如何检查路径是否存在或不在Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文