如何从hdfs中读取文件 [英] How to read the file from hdfs
本文介绍了如何从hdfs中读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在/ project1目录下的hadoop文件系统中有一个文本文件名mr.txt。我需要编写python代码来读取文本文件的第一行,而无需将mr.txt文件下载到本地。但是我无法从hdfs打开mr.txt文件。
我曾尝试过:
I have a text file name mr.txt in the hadoop file sytem under /project1 directory. I need to write the python code to read the first line of the text file without downloading mr.txt file into local. But I have trouble to open the mr.txt file from hdfs. I had tried:
open('hdfs:///project1/mr.txt','r')
推荐答案
获取PySpark安装。
Get PySpark installed.
text = sc.textFile('hdfs:///project1/mr.txt')
first_line = text.first()
这篇关于如何从hdfs中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文