有几种解决办法
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
这个一定有效...
System.setProperty("HADOOP_USER_NAME", "hduser")
- 使用UserGroupInformation
UserGroupInformation ugi = UserGroupInformation.createRemoteUser("hduser");
ugi.doAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
Configuration configuration = new Configuration();
// 写一些东西
FileSystem fs = FileSystem.get(new URI("hdfs://192.168.1.108:9000"), configuration);
Path outFile = new Path("/user/hadoop/test.txt");
FSDataOutputStream out = fs.create(outFile);
BufferedWriter br=new BufferedWriter(new OutputStreamWriter(out));
br.write("This is test string");
br.close();
}
});