title: Writing a two dimensional array to a file in java
body: <p>I am trying to write a two dimensional array to a file using this simple code:</p>
  
  <pre><code>public void writeZ(PrintWriter out) { 
      for(int i=0;i&lt;z.length;i++) {
      int count = 0;
      for (int j=0; j&lt;z[i].length; j++) {
           out.print(z[i][j] + " ");
           count++;
      }
      System.out.print( count);
      out.println();
      }
  }
  </code></pre>
  
  <p><strong>Note</strong>: The <em>count</em> is just for debugging</p>
  
  <p>My problem is that the file size doesn't match the array size.<br>
  The number of lines is correct (45) but the last line as 1643 numbers instead 6006 as in the array.</p>
  
  <p>Any ideas what is the problem?</p>