Java recursive file search
I need help with a method to find a file given a specific parent directory. It needs to take in the parent directory and file to find as arguments, and return the full path to the file or an empty string if the file was not found. Here is what I have so far, it doesn't work :(.
private String findFile(File parentDir, File fileToFind)
{
File[] filesAndDirs = parentDir.listFiles();
for( File file: filesAndDirs )
{
if( file.getName().equals(fileToFind.getName()) )
{
return file.getAbsolutePath();
}
if (!file.isFile())
{
return findFile(file, fileToFind);
}
}
return"";
}

