Tuesday, July 28, 2009

How do i write to an existing file (in Java) without overwriting the current data?

It's for a project, but i need to know how to write to an existing file (in Java) without erasing the data currently in the existing file.

How do i write to an existing file (in Java) without overwriting the current data?
public static void append(){


BufferedWriter bw = null;





try {


bw = new BufferedWriter(new FileWriter("checkbook.txt", true));


bw.write(new Date() + "");


bw.newLine();


bw.flush();


} catch (IOException ioe) {


ioe.printStackTrace();


} finally {


if (bw != null)


try {


bw.close();


} catch (IOException ioe2) {





}


}


}





**************************************...





new FileWriter("checkbook.txt", true)





the second argument is the append flag

flowers online

No comments:

Post a Comment