spark-4-文件读写

hdfs文件读写报错:

AccessControlException: Permission denied: user=root, access=WRITE, inode="/user/chaojunwang":chaojunwang:supergroup:drwxr-xr-x

 

【解决方法】

1. 不要sudo启动hadoop或pyspark

2. 在hadoop路径下  ./bin/hdfs dfs -chmod 777 /user   修改 hdfs 文件系统中/user/chaojunwang 路径的权限

3. 在pyspark中即可完成 hdfs 的文件读写

>>> textFile = sc.textFile("hdfs://localhost:9000/user/chaojunwang/word.txt")
>>> textFile.saveAsTextFile("hdfs://localhost:9000/user/chaojunwang/writeback.txt")
>>> textFile = sc.textFile("hdfs://localhost:9000/user/chaojunwang/writeback.txt")
>>> textFile.first()
'It is a start for me to pyspark learning.'

  

 

posted @ 2020-07-11 19:06  王朝君BITer  阅读(234)  评论(0编辑  收藏  举报