/* * Copyright (c) 2015 Camil Staps */ package com.camilstaps.findfile; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author camilstaps */ public class FileFinder implements Runnable { private final File rootDir; private final String search; public FileFinder(String root, String search) throws IOException { rootDir = new File(root); if (!rootDir.exists() || !rootDir.isDirectory()) { throw new IOException(root + " is not a directory."); } this.search = search; } @Override public void run() { find(rootDir, search); } private void find(File dir, String name) { File[] files = rootDir.listFiles(); if (files == null) return; for (File file : files) { if (file.getName().equals(name)) { System.out.println(file.getAbsolutePath()); } if (file.isDirectory()) { try { Thread t = new Thread(new FileFinder(file.getAbsolutePath(), search)); t.start(); t.join(); } catch (IOException | InterruptedException ex) {} } } } }