import java.util.Properties
import org.apache.log4j.{Level, Logger}
import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.{SparkConf, SparkContext}
object SparkStreamingLocalfile {
def main(args: Array[String]): Unit = {
Logger.getLogger("org.apache.spark").setLevel(Level.WARN);
Logger.getLogger("org.eclipse.jetty.server").setLevel(Level.OFF);
val sparkConf = new SparkConf().setAppName("SparkStreamingLocalfile").setMaster("local[2]");
val ssc = new StreamingContext(sparkConf,Seconds(5))
val fileStream= ssc.fileStream("d:\\temp")
fileStream.print()
val textFileStream=ssc.textFileStream("d:\\temp")
val words = textFileStream.flatMap(_.split(" "))
val wordCounts = words.map(x => (x, 1))
wordCounts.print()
textFileStream.print()
ssc.start()
ssc.awaitTermination()
}
}
试了,还是不行
|