Java gurus....
Discussion
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

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
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
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
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff