title: Iterator writing to File.txt Java
body: <p>Here  is my issue: I need to write the Interator to the file "random.txt" I am able to see all the data. The data is Store where suppose to, I can see it with the System.out.print but my file is in blank. I am able to create the file but not to writer to it. </p>
  
  <p>I am reading a file from my comp. store in the Treemap and trying to write to the text file. ( I am able to doit with Array with not problem) But this Map with Iterator is bouncing my head.</p>
  
  <p>If some one can help me a litter I will appreciated. </p>
  
  <p>I need to use the TreeMap and the Iterator.</p>
  
  <pre><code>public static void main(String[] args) throws FileNotFoundException, IOException {
      Map&lt;String, String&gt; Store = new TreeMap&lt;&gt;();
  
      Scanner text=new Scanner(System.in);
  
      System.out.println("enter file:  ");
  
  
      //C:\Users\Alex\Desktop\Fruits\fruits.txt           
  
      String rap=text.next();
  
      File into = new File(rap);
  
      try (Scanner in = new Scanner(into)) {                
  
          while (in.hasNext()){
              String name=in.next();
              String fruta = in.next();
              Integer num= Integer.parseInt(in.next());
              System.out.println(fruta+"\t"+name+"\t"+num);
  
              if (Store.containsKey(fruta)){
                  Store.put(name,Store.get(name)+fruta );
              }
              else{
                  Store.put(name,fruta);
              }
          }
  
          in.close();
  
      }                                                                
  
      System.out.println();
  
      // insert data to store MAP 
      Set top=Store.entrySet();
      Iterator it = top.iterator();  
  
      // debugging 
  
      System.out.println(top);
  
      // Creating file???????
      FileWriter fstream = new FileWriter("random.txt");  
  
      //identify File to be write?????? 
      BufferedWriter out = new BufferedWriter(fstream);
  
      //iterator Loop       
      while(it.hasNext()) {
  
          Map.Entry m = (Map.Entry)it.next();
          String key = (String)m.getKey();
          String value = (String)m.getValue();
  
          //writing to file?????
          out.write("\t "+key+"\t "+value);
  
          // debugging 
          System.out.println(key +"\t"+ value);
      }       
  
      System.out.println("File created successfully.");
  }
  </code></pre>