FileAppender
Origin
As its name suggests, the FileAppender
class represents a file appender. This object holds a file and appends accumulated data to the file uniformly after a certain amount of data has been accumulated in memory. This class only opens the file when writing to it and closes it after writing is completed. Therefore, this class does not need to be closed.
After calling the append
method, the data is buffered in memory. Only when the buffer is full will the data be written to the file all at once, so there may always be remaining unwritten content in memory. In this case, you must call the flush
method to write the remaining content to the file.
In other words, this is a file appender that supports buffered writing. This class is mainly used for requirements such as log writing.
Usage
FileAppender appender = new FileAppender(file, 16, true);
appender.append("123");
appender.append("abc");
appender.append("xyz");
appender.flush();
appender.toString();