我有String s = "three_v1_FVID121007.jpg".
如何检查C:\
目录或子目录中是否存在此文件?
答案 0 :(得分:4)
File file = new File("three_v1_FVID121007.jpg");
if(file.exists()){
System.out.println("file is already there");
}else{
System.out.println("Not find file ");
}
答案 1 :(得分:0)
使用apache commons-io FileUtils
:
FileUtils.listFiles(
new File("C:\\"), // base dir
new NameFileFilter("three_v1_FVID121007.jpg"), // file filter
TrueFileFilter.INSTANCE // directory filter
).size() == 1;
(未经测试)