Writing to file with Java
<p>I am trying to write a simple method to save my document to a file (overwriting any previous contents of the file.) Unfortunately, my implementation does not seem to work. I am calling it on my document, which is, for all intents and purposes, an array of String. What I'd like to do is to write the contents of my array, with a separate line for each value in the array, the value in position [0] on the first line, and the value for [1] on the second. How would I go about this ?</p>

<p>This is my implementation so far :</p>

<pre><code>  public void save()
   { 
      try
      {
         PrintWriter outputFile = 
            new PrintWriter(new BufferedWriter(new FileWriter(docName)));
         int lineNo = 1;

         while (lineNo != lineNo) // CHANGE THIS!!!
         {  outputFile.println(" ~ ");
            lineNo++;
         }
         outputFile.flush();
      }
      catch (Exception e)
      {
         System.out.println("Document: Touble writing to "+docName);
         System.exit(1);
      }
</code></pre>

<p>}</p>
