Scala 读取文件

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")

  

猜你喜欢

转载自www.cnblogs.com/RHadoop-Hive/p/10064599.html
今日推荐