Java File Find find(File file)

Here you can find the source of find(File file)

Description

find

License

Open Source License

Declaration

public static List<File> find(File file) 

Method Source Code

//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;
    }
}

Related

  1. find(File absolutePath, FileFilter filter)
  2. find(File baseFile, String regex)
  3. find(File dir, String baseName)
  4. find(File dir, String suffix, Set ignore)
  5. find(File file, Pattern pattern, int limit, List found, Set visited)
  6. find(File folder, final String name)
  7. find(File path, Boolean recursive)
  8. find(File root)