Java File Find findJavaFiles(File dir, Collection filenames)

Here you can find the source of findJavaFiles(File dir, Collection filenames)

Description

Recursively finds all the java files in the specified directory and adds them all to the given collection.

License

Apache License

Parameter

Parameter Description
dir The directory.
filenames The collection.

Declaration

private static void findJavaFiles(File dir, Collection<String> filenames) 

Method Source Code

//package com.java2s;
/*/*w ww  .  ja  v a  2 s  .c  o  m*/
 * Copyright 2006-2008 Web Cohesion
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;
import java.io.FileFilter;

import java.util.Collection;

public class Main {
    private static FileFilter JAVA_FILTER = new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".java");
        }
    };
    private static FileFilter DIR_FILTER = new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    };

    /**
     * Recursively finds all the java files in the specified directory and adds them all to the given collection.
     *
     * @param dir       The directory.
     * @param filenames The collection.
     */
    private static void findJavaFiles(File dir, Collection<String> filenames) {
        File[] javaFiles = dir.listFiles(JAVA_FILTER);
        for (File javaFile : javaFiles) {
            filenames.add(javaFile.getAbsolutePath());
        }

        File[] dirs = dir.listFiles(DIR_FILTER);
        for (File dir1 : dirs) {
            findJavaFiles(dir1, filenames);
        }
    }
}

Related

  1. findExecutableInSystemPath(String executable)
  2. findExecutableLocation(String executableName)
  3. findExecutableOnPath(String executable)
  4. findExecutableOnPath(String executableName)
  5. findExecutableOnPath(String executableName)
  6. findJavaFiles(File folder)