Hadoop--学习笔记 在Eclipse中操作远程hdfs文件

来源:互联网 发布:高性能网络编程 二 编辑:程序博客网 时间:2024/05/22 00:20

       最近在学习Hadoop,总结两点:

       1.在运行Mapreduce程序时,设置程序操作hdfs目录而不是本地目录

       2.在运行Mapreduce程序时,每次运行程序前都要删除输出目录下文件名相同的文件,不然就会提示“Exception in thread "main" org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory hdfs://localhost:8020/output/heyu1 already exists”的错误,在网上找了半天也没找到好的解决办法,最后在看《Hadoop实战》时发现源程序里有个类FileSystem,于是尝试了一下果然成功了。

        添加代码如下

//设置操作文件地址为 hdfs 的地址FileSystem.setDefaultUri(conf, "hdfs://localhost:8020");FileSystem fs = FileSystem.get(conf);//如果输出目录存在则删除fs.delete(new Path("/output/heyu1"), true);FileOutputFormat.setOutputPath(conf, new Path("/output/heyu1"));


0 0
原创粉丝点击