Java gurus....
Author
Discussion

aranell

Original Poster:

868 posts

241 months

Wednesday 2nd November 2005
quotequote all
I'm trying (miserably) to code in Java (gah... )

How do I append to the file instead of overwriting everything that's in the file?

I currently have this:
filename = foo.txt;
String blah = "random stuff here";
File outputFile = new File(filename);
BufferedWriter out = new BufferedWriter(new FileWriter(outputFile));
out.write(blah + "*";
out.close();

Why won't they let me use SmallTalk instead?!

- A

docevi1

10,430 posts

265 months

Wednesday 2nd November 2005
quotequote all
Couple of options, you can to read the contents of the file and simply tag your string to the end or when creating the FileWriter simply use FileWriter(String filename, boolean append) constructor (i.e. true)

The beauty of Java is that the API is everywhere, http://java.sun.com/j2se/1.4.2/docs/a and find the relevant method (in this case FileWriter) and look through the constructors. The ugliness of Java is the slow clumbersome operation, but thats another saga

>> Edited by docevi1 on Wednesday 2nd November 21:31

aranell

Original Poster:

868 posts

241 months

Wednesday 2nd November 2005
quotequote all
[redacted]

docevi1

10,430 posts

265 months

Wednesday 2nd November 2005
quotequote all


The joys of Java programming