How can I get a parallel stream Files.walk?

I need to do some read-only processing on all files in a folder recursively. I use Files.walk to get the file stream, but I noticed that the api indicates that walk only returns a regular stream, not a parallel stream.

How can I process all files in a directory in parallel?

+6
source share
1 answer

You can convert any Stream to parallel Stream by calling Stream::parallel .

 Stream<Path> stream = Files.walk(startPath).parallel().forEach(...); 
+15
source

All Articles