Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 4
    This design of mapping the readers themselves is going to lead to problems. Better to deal with the file reading all in one single lambda. Avoid having a Stream<FileReader> in the first place. Commented Apr 19, 2017 at 19:06
  • @LouisWasserman You mean more problems than this one? Which? Commented Apr 19, 2017 at 19:08
  • 3
    Eh, it's just generally good practice to control the entire lifetime of readers and the like with one try-with-resources statement. Commented Apr 19, 2017 at 19:09
  • 2
    What I'm saying is that you're intended not to design your stream that way. (To say nothing of the complexities of trying to do I/O operations midstream...) You might be able to hack it together by maybe doing a close operation in that flatMap of yours, but it's still going to be much more awkward than trying to do this with a single try-with-resources lambda. Commented Apr 19, 2017 at 19:12
  • 1
    This is the typical case where I prefer the old imperative approach rather than shooting my own foot by using streams. Or, if you insist on using streams, I'd move all the file handling to private methods. Commented Apr 19, 2017 at 19:49