[java] reading a file, then appending to it

Associate
Joined
23 Aug 2004
Posts
1,493
Hey,

basically creating a multiple choice system. I'm storing the results from tests in a file called results.txt. I've setup the file and when it takes a test, it writes to it perfectly. However, when I start a new test, it blanks the file and starts again rather than appending to the file.

I think i need to read the file first and then append to it. Anyone suggest how I'd do that, can't quite figure it out?

Thanks.

----------------------

Solved, just needed to open the file in append mode like this;

Code:
out = new BufferedWriter(new FileWriter("results.txt", true));
 
Last edited:
off the top of my head:

//append to textfile

try
{
BufferedWriter out = new BufferedWriter(new FileWriter("filename", true));
out.write("aString");
out.close();
}
catch (IOException e)
{
}

EDIT: damn, too slow lol

SiriusB
 
Back
Top Bottom