1

Because I asked wrong question last time, I want to correct my intention. How can I find file by name in specified folder? I have a variable with a name of this file and i want to find it in specified folder. Any ideas?

Community
  • 1
  • 1
edi233
  • 3,511
  • 13
  • 56
  • 97
  • Have a look at http://stackoverflow.com/questions/5751335/using-file-listfiles-with-filenameextensionfilter – jackrabbit Nov 12 '11 at 16:44

2 Answers2

5

Maybe the simplest thing that works is:

String dirPath = "path/to/directory";
String fileName = "foo.txt";
boolean fileExistsInDir = new File( dirPath, fileName ).exists();

File is just a placeholder for a location in the file system. The location does not have to exist.

jackrabbit
  • 5,525
  • 1
  • 27
  • 38
2

Use Finding files in Java as a starting point. It should have everything that you are looking for - ask another specific question if you get stuck.

AbdullahC
  • 6,649
  • 3
  • 27
  • 43