Here you can find the source of find(File file)
public static List<File> find(File file)
//package com.java2s; /**//from www .j av a 2s . c om * This file is part of SmallNN, a small neural network implementation * Copyright (C) 2011, 2012 Arsen Kostenko <arsen.kostenko@gmail.com> * * SmallNN is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SmallNN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with SmallNN. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.FileFilter; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; public class Main { public static List<File> find(File file) { return find(file, null); } public static List<File> find(File file, FileFilter filter) { List<File> result = new ArrayList<File>(); LinkedList<File> stack = new LinkedList<File>(); stack.push(file); while (!stack.isEmpty()) { File f = stack.pop(); if (filter == null || filter.accept(f)) { result.add(f); } if (f.isDirectory() && f.exists()) { stack.addAll(Arrays.asList(f.listFiles())); } } return result; } }