user835956
user835956

Reputation: 43

scala : getwords similar to getlines

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

Answers (1)

Andrew Cassidy
Andrew Cassidy

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

Related Questions