Skip to content

Instantly share code, notes, and snippets.

@orhanobut
Last active December 23, 2015 12:49
Show Gist options
  • Save orhanobut/6637894 to your computer and use it in GitHub Desktop.
Save orhanobut/6637894 to your computer and use it in GitHub Desktop.
Find a file in the given directory Complexity = O(n!)
public static File findFile(File file, String fileName){
File[] files = file.listFiles();
if (files == null) return null;
for (File f : files){
if (f.isFile() && f.getName().equals(fileName)){
return f;
} else if (f.isDirectory()){
return findFile(f, fileName);
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment