首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hadoop文件读取

Hadoop文件读取
EN

Stack Overflow用户
提问于 2014-08-25 18:16:01
回答 1查看 50关注 0票数 0

Hadoop 2.2.0中的hadoop分布式缓存字数示例。已将文件复制到hdfs文件系统,以便在mapper类的设置中使用。

代码语言:javascript
复制
protected void setup(Context context) throws IOException,InterruptedException 
{
      Path[] uris = DistributedCache.getLocalCacheFiles(context.getConfiguration());
      cacheData=new HashMap<String, String>();

      for(Path urifile: uris)
      {   
      try
      {

        BufferedReader readBuffer1 = new BufferedReader(new FileReader(urifile.toString()));
        String line;
        while ((line=readBuffer1.readLine())!=null)
        {      System.out.println("**************"+line);
               cacheData.put(line,line);
        }
        readBuffer1.close(); 
        }       
       catch (Exception e)
       {
                  System.out.println(e.toString());
       }
      }

}

内部驱动程序主类

代码语言:javascript
复制
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf,args).getRemainingArgs();
    if (otherArgs.length != 3)
    {
      System.err.println("Usage: wordcount <in> <out>");
      System.exit(2);
    }
    Job job = new Job(conf, "word_count");
    job.setJarByClass(WordCount.class);
    job.setMapperClass(Map.class);
    job.setReducerClass(Reduce.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
    Path outputpath=new Path(otherArgs[1]);
    outputpath.getFileSystem(conf).delete(outputpath,true);
    FileOutputFormat.setOutputPath(job,outputpath);
    System.out.println("CachePath****************"+otherArgs[2]);
    DistributedCache.addCacheFile(new URI(otherArgs[2]),job.getConfiguration());
    System.exit(job.waitForCompletion(true) ? 0 : 1);

但是得到了异常

java.io.FileNotFoundException: file:/home/user12/tmp/mapred/local/1408960542382/cache (没有这样的文件或目录)

因此缓存功能无法正常工作。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2014-08-26 15:52:04

解决了这个问题。错误地指定了文件位置。现在工作得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25483677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档