title: Export array values to csv file java
body: <p>I just need help exporting array elements to a csv file. I don't know what's wrong with my code. Any help is gladly appreciated. Thanks.</p>
  
  <pre><code>for (int index = 0; index &lt; cols.length; index++)
  {
      FileWriter fw = new FileWriter(newFileName);
      if (index == cols.length - 1)
      {
          fw.append(cols[index]);
      }
      else
      {
          fw.append(cols[index]);
          fw.append(",");
      }
  
  }
  </code></pre>
  
  <p>When I run this. Nothing happens to my csv file. Infact, it wipes everything of. Please help.</p>