Scala 读取文件
生活随笔
收集整理的這篇文章主要介紹了
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")
轉載于:https://www.cnblogs.com/RHadoop-Hive/p/10064599.html
總結
以上是生活随笔為你收集整理的Scala 读取文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【git】之使用shell脚本提交代码
- 下一篇: Matplot的常见问题