Java Stream How to - Output directory with lambda








Question

We would like to know how to output directory with lambda.

Answer

/*from w ww .  ja va  2  s.c om*/
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;


public class Main {

    public static void main(String[] args) {
        final String dir = "C:\\data\\projects\\";
        final Path path = Paths.get(dir);
        final File file = path.toFile();
        Stream.of(file.listFiles(File::isDirectory))
            .forEach(System.out::println);;
    }
}