java追加到文件末尾
Today we will look into how to append to a file in java. Java append to file is a common java IO operation. For example, whenever we print something to server logs, it gets appended to the existing file.
今天,我们将研究如何在Java中附加文件。 Java追加到文件是一种常见的Java IO操作。 例如,每当我们将某些内容打印到服务器日志时,它就会被附加到现有文件中。
Java追加到文件 (Java append to file)
We can append to file in java using following classes.
我们可以使用以下类在Java中追加文件。
- Java append to file using
FileWriter
Java使用FileWriter
附加到文件 - Java append content to existing file using
BufferedWriter
Java使用BufferedWriter
将内容追加到现有文件 - Append text to file in java using
PrintWriter
使用PrintWriter
将文本追加到Java中的文件 - Append to file in java using
FileOutputStream
使用FileOutputStream
附加到Java中的文件
If you are working on text data and the number of write operations is less, use FileWriter and use its constructor with append flag value as true
. If the number of write operations is huge, you should use the BufferedWriter.
如果您正在处理文本数据并且写入操作的次数较少,请使用FileWriter并将其构造函数的附加标志值设置为true
。 如果写入操作的数量很多,则应使用BufferedWriter 。
To append binary or raw stream data to an existing file, you should use Fi