Possible Duplicate:
How to append text to an existing file in Java
How can I add a string to the end of a .txt file?
Possible Duplicate:
How to append text to an existing file in Java
How can I add a string to the end of a .txt file?
From here
BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter("checkbook.txt", true)); bw.write("400:08311998:Inprise Corporation:249.95"); bw.newLine(); bw.flush(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { // always close the file if (bw != null) { try { bw.close(); } catch (IOException ioe2) { // just ignore it } } } As advised by Joachim Sauer, instead of using FileWriter, you can use
new OutputStreamWriter(new FileOutputStream(..), ecnoding) if you want to specify the encoding of the file. FileWriter uses the default encoding, which changes from installation to installation.
FileWriter means that you're pretty much ignoring the entire [encoding problem](joelonsoftware.com/articles/Unicode.html], which is a dangerous thing to do!English term to look for: "append"
You need to perform the following steps:
Read about the FileOutputStream class.
FileOutputStream alone is the wrong tool when you want to write text to a .txt file. You will want to use a Writer. In this case you want to use a OutputStreamWriter wrapped around a FileOutputStream (there's also the FileWriter, but it's broken since it doesn't support specifying an encoding).