Read a TextFile Using Spark Scala
Reading a text file in Spark Scala is straightforward. You can use the textFile
method.
import org.apache.spark.sql.SparkSession object ReadTextFile { def main(args: Array[String]): Unit = { val sparkSession = SparkSession .builder() .appName("Our First scala spark code") .master("local") .getOrCreate() val salesDF = sparkSession.read.textFile("data/text/data.txt") salesDF.show(false) sparkSession.stop() } }
Output: