I am trying to write an array to a file and having difficulties understanding it
<p>So the code I first used to attempt this goes as follows</p>

<pre><code>public static void writeArrayToFile( String fileName) 
{ 
 int [] data = {1,2,3,4,5,6}; 

 try 
 { 
  // wrap fileWritter in bufferedWriter 
  FileWriter fileWriter = new FileWriter(fileName); 
  BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); 

  for(int i=0;i&lt;data.length;i++) 
  { 
   bufferedWriter.write(data[i]); 
   bufferedWriter.newLine(); 
  } 
 } 

 catch(IOException ex) 
 { 
  System.out.println("Error writing to file '" + fileName + "'"); 
 }

}
</code></pre>

<p>This code executes and does not throw errors while creating the file specified however does not fill the file with the array. What is it that is wrong with the following code?</p>

<p>I was able to find working code that I implemented which solved the issue however don't understand why this code doesn't work. Also if I run the program twice why does the array not appear twice and only once while making changes to the array updates the existing file with the changes but the old array is gone?</p>