This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
You haven't shown us what sort of object "out" is, with its "append" method. I'm guessing it's an instance of java.io.FileWriter; in that case, note that append() is exactly the same as write() -- it does nothing special.
What matters is not whether you call append(), but how you construct the FileWriter. There's a constructor that takes a boolean argument after the filename; if you pass "true" for that argument, then the FileWriter appends to the end of the file. If you pass false, or use any other constructor, then the FileWriter erases the prior contents of the file the instant the FileWriter is created.
So if you do something like
FileWriter out = new FileWriter("myfile.txt"); out.write("Hello"); out.close(); out = new FileWriter("myfile.txt", true); out.write(", world!"); out.close();
The trick is in creating the FileWriter. There are two constructors that take a boolean. If this boolean is true, everything you write to that file is appended. If it is false, or you use a constructor without the boolean, you will overwrite the file.
In other words, just what Ernest has just said [ April 06, 2008: Message edited by: Rob Prime ]