-2

I have String s = "three_v1_FVID121007.jpg".

How can I check if this file exists in the C:\ directory or subdirectories?

cahen
  • 15,807
  • 13
  • 47
  • 78
Vitaliy Mckay
  • 163
  • 2
  • 13
  • It is unclear what you are asking. Do you want to check if the file "C:\three_v1_FVID121007.jpg" exists on disk? – Tunaki Aug 13 '15 at 11:36
  • Tunaki, its not quite a duplicate because this one is looking for a search, whereas the other one's input is a path. But its the same concept and can probably be used to answer this question. – 10 Replies Aug 13 '15 at 11:39

2 Answers2

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 ");
  }
Anand Dwivedi
  • 1,452
  • 13
  • 23
0

With 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;

(not tested)