New to Java 8 and practicing Streams
and Lambdas
.
I am trying to create a Stream<String>
out of a folder files content. This is something that I tried unsuccessfully:
Stream<String> lineStream = Files.walk(Paths.get("resources")).flatMap(Files::lines);
The compiler yells that I am not catching an IOException
even if I have a throws clause. Can anyone explain this to me?
I managed to print all the files that I am interested in with the following:
Files.walk(Paths.get("resources"))
.map(Path::toFile)
.filter(File::isFile)
.forEach(System.out::println);
How do I get a Stream<String>
with each String
being a line of the files printed by the code above?