import java.io.File; public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub File file = new File("D:/"); System.out.println(findFile(file, "1.txt")); } private static String findFile(File baseFile, String fileName) { File[] listFiles = baseFile.listFiles(); String resultPath = null; if (listFiles == null) { return null; } for (int i = 0; i < listFiles.length; i++) { File file = listFiles[i]; if (file.isDirectory()) { resultPath = findFile(file, fileName); if (resultPath != null) { return resultPath; } }else { if (file.getName().equalsIgnoreCase(fileName)) { return file.getAbsolutePath(); } } } return null; } }