How to update a file in Java?
October 12, 2007
I’ve been reading books in Java just to find a code on how to update a file just to append a text in it. A lot of code fragments on Java File available but it just give you how to write a file alone, and or how to read a file alone. This article will help you to create at the same time append a text to an existing file.
Here’s a sample of simple and short Java code to create (if not created) and append a file if existing.
public void createOrAppendFile (File f, String text) throws IOException {
BufferedWriter bw = new BufferedWriter (new FileWriter (File, true));
bw.write (text);
bw.newLine();
bw.flush();
bw.close();
}
July 29, 2008 at 7:07 am
i have a file with different columns and ten records. if i want to update the record no.5 then do i need delete the whole file. if so what about my other 9 records which got inserted automatically from my jsp page.
April 30, 2009 at 8:28 am
Mate thankyou so so so much you cannot now how much I needed this
Your a genius
Cheers
Dan
June 17, 2009 at 2:36 pm
thanks a lot yaar.it really helped me.