【问题标题】:Hadoop File ReadHadoop 文件读取
【发布时间】:2014-08-25 10:16:01
【问题描述】:

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

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());
       }
      }

}

内部驱动主类

    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(没有这样的文件或目录)

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

【问题讨论】:

    标签: hadoop


    【解决方案1】:

    解决了这个问题。 错误地给出了文件位置。 现在工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-28
      • 2013-04-08
      相关资源
      最近更新 更多