edi233
edi233

Reputation: 3031

Files searching in Java

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?

Upvotes: 1

Views: 476

Answers (2)

jackrabbit
jackrabbit

Reputation: 5653

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.

Upvotes: 5

AbdullahC
AbdullahC

Reputation: 6730

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.

Upvotes: 2

Related Questions