开发者

how to use append function in file

开发者 https://www.devze.com 2023-01-02 09:35 出处:网络
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

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消