You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It might be hard to implement it that way since b.f.File.lines is returning an iterator (which is nice since it allows for very elegant programming). I've not much knowledge about auto-closables but I thought when using them, the consumption of the file content would need to happen in a scope, which would reduce the beauty/readability of File.lines.
I totally agree about potential performance issues when using java.nio.Files.allLines as backend for b.f.File.lines but at least programs would not die after a while when using it. The provided links indicate that nio.Files.lines API design is misleading to many users and maybe b.f could do a better job by providing
a file line iterator (e.g. .linesIterator) by which enforces file closing via some auto-closable.
a more simplistic .lines method which simply returns a List[String]
Example:
will die inevitably with a "Too many open files in system" error.
The solution would be to use some closable or even simpler to use
Files.readAllLines
instead ofFiles.lines
See also
http://www.rationaljava.com/2015/02/java-8-pitfall-beware-of-fileslines.html
https://bugs.openjdk.java.net/browse/JDK-8073923
The text was updated successfully, but these errors were encountered: