7.1 读写 Text 文件
// 读取本地文件
scala> val rdd1 = sc.textFile("./words.txt")
rdd1: org.apache.spark.rdd.RDD[String] = ./words.txt MapPartitionsRDD[5] at textFile at <console>:24
scala> val rdd2 = rdd1.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_ +_)
rdd2: org.apache.spark.rdd.RDD[(String, Int)] = ShuffledRDD[8] at reduceByKey at <console>:26
// 保存数据到 hdfs 上.
scala> rdd2.saveAsTextFile("hdfs://hadoop201:9000/words_output")