[英]How to Prevent PrintWriter from overwriting a file in Java
How can i prevent prinwriter in java from overwriting what's inside of that particular file? 我如何防止Java中的prinwriter覆盖该特定文件中的内容?
Ex. 例如 I have a
student.txt
file. 我有一个
student.txt
文件。 I already have few names there. 我那里已经有几个名字了。 After running and modifying this How do I create a file and write to it in Java?
运行并修改此文件后,如何创建文件并用Java写入文件? whats inside of that file will be overwritten.
该文件中的内容将被覆盖。 I just want to add it to the new line.
我只想将其添加到新行中。
Also, how can i possibly perform search? 另外,我怎么可能执行搜索?
PrintWriter out = new PrintWriter(new FileWriter("student.txt", true));
The true
is the append
parameter - which indicates whether the FileWriter should append to the file. true
是append
参数-指示FileWriter是否应附加到文件。 If it was false
it would overwrite existing data in the file. 如果为
false
,它将覆盖文件中的现有数据。
What do you mean by "how can i possibly perform search"? “我怎么可能执行搜索”是什么意思?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.