writing file to java issue
<p>I have a java program that writes a file using the BufferedReader, however, at the end of the file it always ends up as it was not finished. Something like as follows:</p>

<pre><code>41,21,true,30,2010-08-07,Answer
2239,1163,true,10,2010-10-06,Answer
641,364,true,10,2010-09-02,Answer
715,149,true,5,2010-08-11,Comment
219,177,true,25,2010-07-23,Answer
4809,4591,true,10,2011-02-11,Answer
4086,4853,true,10,2011-02-17,Answer
3720,2611,true,10,2010-12-08,Answer
5101,60,true,5,2011-03-07,Comment
1393,689,true,20,2010-08-24,Answer
1274,450,true,5,2010-08-09,Comment
446,4853,true,5,2011-03-07,Comment
2191,70,true,5,2011-02-05,Comment
1487,1281,true,10,2010-08-05,Answer
3479,3899,true,10,2010-12-25,Answer
1393,685,true,10,2010-07-26,Answer
364,649,true,5,2010-07-19,Comment
1274,1236,true,10,2010-08-19,Answer
99,18
</code></pre>

<p>How could this have happened? Most of my programs are executing it inside a loop. Here's part of it:</p>

<pre><code>try {
                output.write("nodedef&gt;name VARCHAR,label VARCHAR,age INT,reputation INT,location VARCHAR(100),upvote INT,downvote INT,creationDate VARCHAR\n");
                Iterator&lt;Integer&gt; itr = set.iterator();

                while(itr.hasNext()){
                  Users temp = users.get(Integer.parseInt(itr.next().toString()));
                  if (temp != null)
                      output.write(temp.id + ", " + temp.displayName + "," + temp.age + "," + temp.reputation + "," + temp.location + "," + temp.upVotes + "," + temp.downVotes + "," + temp.date + "\n" );
                }

                output.write("edgedef&gt;node1 VARCHAR,node2 VARCHAR,directed BOOLEAN, weight DOUBLE, creationDate VARCHAR, postType VARCHAR\n");
                Enumeration&lt;Edges&gt; h = edges.elements();
                while (h.hasMoreElements()){
                    Edges edge = h.nextElement();
                    output.write(edge.sourceUserId + "," + edge.targetUserId + ",true," + edge.weight + "," + edge.creationDate + "," +  edge.type + "\n");
                }
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
</code></pre>
