title: How to save the input of a Reducer as a file on the Reducer machine and then access it again in the same reduce phase
body: <p>I am trying to implement decision tree using <em>mapreduce</em>. In my reduce phase I want to save the output of my mapper in a <code>.data</code> file, and then again access it in the same reducer.</p>
  
  <p>Since I require the data in form of instance for which I require <code>*.data</code> file and not the array of string provided by mapper as output.</p>
  
  <p>This is what I am doing right now:</p>
  
  <pre class="lang-java prettyprint-override"><code>public void reduce(LongWritable key, Iterable&lt;Text&gt; values, Context context)  
      throws IOException, InterruptedException 
  {
      Writer writer = null;
      writer = new BufferedWriter(new OutputStreamWriter(
                      new FileOutputStream( key+"/temp.data"), "utf-8")
      );
      for (Text val : values) {
              writer.write( val.toString() + "\n");
      }
  }
  </code></pre>