How do I read a large CSV file (> 1 Gb) with a Scala Stream? Do you have a code example? Or would you use a different way to read a large CSV file without loading it into memory first?
Just use Source.fromFile(...).getLines
as you already stated.
That returns an Iterator, which is already lazy (You'd use stream as a lazy collection where you wanted previously retrieved values to be memoized, so you can read them again)
If you're getting memory problems, then the problem will lie in what you're doing after getLines. Any operation like toList
, which forces a strict collection, will cause the problem.