All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.pdx.cs.joy.java8.FindJavaFilesUsingJava8 Maven / Gradle / Ivy

The newest version!
package edu.pdx.cs.joy.java8;

import java.io.File;
import java.util.Arrays;

/**
 * This program demonstrates how Lambdas in Java 8 greatly simplify using
 * "functional interfaces" like FileFilter and
 * FileNameFilter.
 *
 * @since Summer 2014
 */
public class FindJavaFilesUsingJava8 {

  /**
   * Prints out the names all of the Java source files in a directory
   * and then recurses over subdirectories.
   */
  private static void findJavaFiles(File directory) {
    File[] javaFiles = directory.listFiles((dir, name) -> name.endsWith(".java"));
    Arrays.asList(javaFiles).forEach(System.out::println);

    File[] subdirectories = directory.listFiles(File::isDirectory);
    Arrays.asList(subdirectories).forEach(FindJavaFilesUsingJava8::findJavaFiles);
  }

  /**
   * The one command line parameter is the directory in which to start
   * the search.
   */
  public static void main(String[] args) {
    File file = new File(args[0]);
    if (file.isDirectory()) {
      // Look for Java files
      findJavaFiles(file);

    } else {
      System.err.println(file + " is not a directory");
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy