I want to write in a file but in a way that it should not delete e开发者_Python百科xisting 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
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();
精彩评论