FileSearch { public void searchByFileName(String fileName, File scanFilePath, List<File> outList) { if (scanFilePath.isFile()) { if (fileName.equals(scanFilePath.getName())) { outList.add(scanFilePath); return; } } else { if (scanFilePath.isDirectory()) { File[] files = scanFilePath.listFiles(); for (int i = 0; i < files.length; i++) { File oneFile = files[i]; searchByFileName(fileName, oneFile, outList); } } } }  void searchByFileName(String fileName, File scanFilePath, List<File> outList); static void main(String[] args);  }
@Test public void searchManyFile() { String fileName = "aa.txt"; File scanFilePath = new File(this.getClass().getResource("file/").getPath()); List<File> outList = new ArrayList<File>(); new FileSearch().searchByFileName(fileName, scanFilePath, outList); for(int i =0;i<outList.size();i++) { Assert.assertEquals("equal", "aa.txt", outList.get(i).getName()); System.out.println(outList.get(i).getAbsolutePath()); } }