import scala.io.Source val inputFile = Source.fromFile("output.txt") val lines = inputFile.getLines for (line <- lines) println(line)
//1、本地文件讀取 val local_file_1 = sc.textFile("/home/hadoop/sp.txt") val local_file_2 = sc.textFile("file://home/hadoop/sp.txt") //2、當前目錄下的文件 val file1 = sc.textFile("sp.txt") //3、HDFS文件 val hdfs_file1 = sc.textFile("hdfs://192.168.66.81:9000/data/input/sp.txt") //4、多文件讀取 val file2 = sc.textFile("sp.txt,a.txt,b.txt") //5、全目錄讀取 val hdfs_file2 = sc.textFile("hdfs://192.168.66.81:9000/data/input/") //6、通配符匹配 val file2 = sc.textFile("file://home/hadoop/*.txt") //7、讀取壓縮文件 val file3 = sc.textFile("file://home/hadoop/sp.gz")