willian
18702515157@163.com

1:hadoop线上集群环境以搭建完毕(不会的同学可以去我的这篇博客http://blog.csdn.net/qq_30259339/article/details/51399744)

2:将安装hadoop版本中的common文件夹中的common.jar和其中lib依赖,和hdfs中的hdfs-client.jar和其中lib的依赖

3:代码如下:

        Configuration configuration = new Configuration();
configuration.set("fs.defaultFS","hdfs://master:9000");
// fs = FileSystem.get(configuration);
fs = FileSystem.get(new URI("hdfs://master:9000"),configuration,"hadoop"); //hadoop是指hadoop用户进行连接

上面时获取fs对象,你可以到这里打断点,看到底fs时哪个类的实例,如果fs时时图片中的实例,说明你成功连接上hdfs

如果是localfileSystem说明你连接失败

4:函数讲解
:fs.delete(new Path(),true);
//第一个参数是hdfs的路径,第二个参数是是否递归删除
posted on 2016-11-24 09:56  willian_zhang  阅读(177)  评论(0编辑  收藏  举报