tags:

views:

38

answers:

1

I want to write in a file but in a way that it should not delete existing data in that file rather it should append that file. Can anybody please help by giving any example related to appending a file? Thank you

+3  A: 

You should use the FileWriter(File file, boolean append) constructor with the boolean value true.

Example

File file = new File("c:/tmp/foo.txt");
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
pw.println("Hello, World");
pw.close();
Adamski
can you please provide me full code including import statements etc because i am having problem in understanding and running this code. thanks
sadia
import java.io.*;
Jin Kim
no sir i asked for the complete code. not only the import statement.
sadia
this error is shown in my program when i compile it:cannot find symbolsymbol : constructor FileWriter(boolean,boolean)location: class java.io.FileWriter PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file, true))); 1 error
sadia
The compiler error suggests you are passing in two booleans rather than a File parameter and a boolean.
Adamski