二、代码实现
package spark;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.FlatMapFunction;
import org.apache.spark.api.java.function.Function;
import scala.Tuple2;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class SparkWordCountForJava {
public static void main(String[] args) {
// 初始化spark , local[]:以核心数在本地运行
SparkConf conf = new SparkConf().setMaster(“local[*]”).setAppName(“SparkWordCountForJava”);
JavaSparkContext jsc = new JavaSparkContext(conf);
JavaRDD textFileRdd = jsc.textFile(“C:\Users\com\Desktop\test.txt”);
// 将数据按照切分规则分成一个个单词
JavaRDD flatMapRdd = textFileRdd.fl