Hadoop放在centos7虛擬機上
本地為window10
在將檔案222.txt上傳到Hadoop時報錯

百度搜索后大佬們說是權限不夠
大佬們給出的解決方案:
1. 修改權限為777
這個太不靠譜了,pass,
2. System.setProperty("HADOOP_USER_NAME", "用戶名")
這個我搞了半天也不知道是啥意思,我把這行代碼放進去,依然報錯同樣的問題,
最終解決方案
在鏈接Hadoop時
源代碼:
public void init() throws Exception {
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://localhost:9000");
fs = FileSystem.get(conf);
}
修改最后一行
修改后:
public void init() throws Exception {
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://localhost:9000");
fs = FileSystem.get(new URI("hdfs://localhost:9000"), conf, "root");
}
再次運行

沒有報錯
檔案已上傳
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/344158.html
標籤:其他
