在IDEA里面编写Code,在HDFS上来创建一个目录。
2.源代码: //c/s
@Before
public void conn() throws Exception {
Configuration conf = new Configuration(true);
FileSystem fs = FileSystem.get(conf);
//FileSystem fs = FileSystem.get(java.net.URI.create("hdfs://mycluster/"), this.conf,"god");
}
@Test
public void mkdir() throws Exception {
Path dir = new Path("/msb");
if (fs.exists(dir)){
fs.delete(dir,true);
}
fs.mkdirs(dir);
}
3.报错:
java.lang.NullPointerException at com.msb.hadoop.hdfs.TestHDFS.mkdir(TestHDFS.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)4.解决方案:
修改为:
conf = new Configuration(true); fs = FileSystem.get(conf);5.成功运行
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Process finished with exit code 0



