Is there some clean static method to just dump (append) a string to a file?
+1
A:
Yes, see the documentation for FileWriter. Set the second argument to true to append to a file.
Swingley
2009-08-06 16:04:07
That's not a clean static method, that's a block of code you need to write, cinluding stream handling, closing, etc.
skaffman
2009-08-06 16:05:37
+2
A:
No, the closest I am aware of is:
FileWriter writer = new FileWriter(fname, true);
writer.append(yourString);
writer.close();
It's not clean or static, but neither is it the most painful code. :)
James M.
2009-08-06 16:21:27
A:
Use a PrintWriter
like this
FileWriter fileWriter = new FileWriter(fileName, true); // true for append
PrintWriter printWriter = new PrintWriter(fileWriter);
printWriter.append(string);
printWriter.close();
Edit: Sorry I didn't check the right Javadoc for FileWriter. Nowadays it seems to have an append method.
So the PrintWriter isn't really necessary if all you want to do is append.
zockman
2009-08-06 16:35:06