如何在文件中使用追加功能

如何在文件中使用追加功能

问题描述:

我想写入一个文件,但不应该删除该文件中的现有数据,而应该追加该文件。任何人都可以通过提供任何与附加文件相关的示例来帮助吗?谢谢如何在文件中使用追加功能

+1

http://stackoverflow.com/questions/2738448/java-io-how-to-append-to-an-already-existing-text-file已经回答 – Poindexter 2010-06-01 16:34:05

您应该使用FileWriter(File file, boolean append)构造函数的布尔值true

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

可以您请向我提供完整的代码,包括导入声明等,因为我在理解和运行此代码时遇到问题。谢谢 – sadia 2010-06-01 16:53:53

+0

import java.io. *; – 2010-06-01 16:59:39

+0

不,先生我问完整的代码。不仅是进口声明。在我的计划显示 – sadia 2010-06-01 17:04:18