title: Write CSV file column-by-column
body: <p>I was searching for an answer for this but I didn't find it. Does anyone have a solution for this kind of problem. I have a set of text variables that I have to write into the .CSV file using Java. I am currently doing a project with JavaScript that calls for Java. This is a function that I have right now that does the job well and writes the text into .CSV line by line.</p>
  
  <pre><code>function writeFile(filename, data)
  {
     try
     { 
  
        //write the data
  
        out = new java.io.BufferedWriter(new java.io.FileWriter(filename, true));
        out.newLine();
        out.write(data);
        out.close();
        out=null;
     }
     catch(e)   //catch and report any errors
     {
        alert(""+e);
     }
  }
  </code></pre>
  
  <p>But now I have to write parts of text one by one like the example bellow.</p>
  
  <pre><code>first0,second0,third0
  first1,second1,third1
  first2,second2,third2
  .
  .
  .
  first9,second9,third9
  </code></pre>
  
  <p>So the algorithm goes like this. The function writes first0 with comma then goes to the next line writes first1, goes to next line writes first2 and so one until first9. After that part is done the script goes to the beginning of the file and writes second0 behind the comma, goes to the next line and writes second1 behind the comma and so on. You get the idea. </p>
  
  <p>So now I need java</p>