I am trying to write to a text file multiple times while saving the previously entered info. I've been searching the web for solutions, but haven't been able to find any. The problem I am having right now is that the output is not comming out correctly.
When you read in the while condition what happens to the line you read? See if this makes sense:
Back in mainframe days we used to call that a "primer read" plus the read in the loop. But nowadays we try to eliminate duplication and this is a more common syntax:
The first time you read this it probably makes no sense. The trick is that an assignment statement like "line = br.readLine()" also returns the value that was assigned, rather like a function. So we can stuff the value of the readLine() into the variable "line" and check it for null in one line of code.
There is another read() right before the loop. Does that one also throw away some data?
After all that, we probably don't need this read and write scheme at all. Look into the optional second argument on the FileWriter constructor.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Okay, thanks it's working properly now. I don't know why I even had the for loop in the first place. I took out the loop and now it works. P.S. Now I understand what you mean about the first part being a waste with the second version of the constructor. I just removed that whole first try catch. Thanks again!
[ March 25, 2006: Message edited by: Al Stumpel ]
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop