title: Hadoop File Read
body: <p>Hadoop  Distributed Cache Wordcount example in hadoop 2.2.0.
  Copied file into hdfs filesystem to be used inside setup of mapper class.</p>
  
  <pre><code>protected void setup(Context context) throws IOException,InterruptedException 
  {
        Path[] uris = DistributedCache.getLocalCacheFiles(context.getConfiguration());
        cacheData=new HashMap&lt;String, String&gt;();
  
        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());
         }
        }
  
  }
  </code></pre>
  
  <p>Inside Driver Main class</p>
  
  <pre><code>    Configuration conf = new Configuration();
      String[] otherArgs = new GenericOptionsParser(conf,args).getRemainingArgs();
      if (otherArgs.length != 3)
      {
        System.err.println("Usage: wordcount &lt;in&gt; &lt;out&gt;");
        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);
  </code></pre>
  
  <p>But getting exception </p>
  
  <p>java.io.FileNotFoundException: file:/home/user12/tmp/mapred/local/1408960542382/cache (No such file or directory)</p>
  
  <p>So Cache functionality not working properly.
  Any Idea ?</p>