Reputation: 43
I want to write a piece of code that looks like following :
var wordItr = Source.fromFile("myfile").getWords
while (wordItr.hasNext) {
val word = wordItr.next
process(word)
}
Reason behind this logic is "myfile" file is really big (around 10GB) and has no line breaks and writing a code like above really helps.
Can you please suggest how to code wordItr
Upvotes: 0
Views: 176
Reputation: 2998
Source.fromFile("myfile").getLines.flatMap(_.split(" "))
or
import java.io.File
import java.util.Scanner
var wordItr = new Scanner(new File("myFile")).useDelimiter(" ")
Upvotes: 3