Here you can find the source of findFile(String basePath, final String fileName)
public static File findFile(String basePath, final String fileName) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; public class Main { /**//from w w w . jav a 2s .co m * TODO dir cache */ public static File findFile(String basePath, final String fileName) throws IOException { Path startPath = Paths.get(basePath); final List<File> fileResult = new ArrayList<>(); // search directories Files.walkFileTree(startPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { if (file.toFile().getName().equalsIgnoreCase(fileName)) { fileResult.add(file.toFile()); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException e) { return FileVisitResult.CONTINUE; } }); // checks result if (fileResult.isEmpty()) { return null; } return fileResult.get(0); } }