【发布时间】:2019-11-06 13:25:41
【问题描述】:
我正在尝试读取如下所示的文件:
you 0.0432052044116
i 0.0391075831328
the 0.0328010698268
to 0.0237549924919
a 0.0209682886489
it 0.0198104294359
例如,我想将它存储在带有 (you,0.0432) 的 RDD (key,value) 中。 目前我只做了那个算法
val filename = "freq2.txt"
try {
for (line <- Source.fromFile(filename).getLines()) {
val tuple = line.split(" ")
val key = tuple(0)
val words = tuple(1)
println(s"${key}")
println(s"${words}")
}
} catch {
case ex: FileNotFoundException => println("Couldn't find that file.")
case ex: IOException => println("Had an IOException trying to read that file")
}
但我不知道如何存储数据...
【问题讨论】:
标签: scala apache-spark