This second argument is for the Boolean append flag, and it’s done to indicate that we’re trying to append to an existing file. We also need to pass true as a second argument to its constructor. The string first needs to be converted to an array of bytes before writing you can use the getBytes() method for this purpose. It is mostly preferred for primitive data types like int or float, but it can also be used for writing character-oriented data. The FileOutputStream class is used to write binary data to files. Append Text to a Text File Using the FileOutputStream Class in Java In this article, we’ll learn about the four different ways to append to a text file. There are several ways of writing or appending data to a file in Java. Reading and writing are two of the most basic operations you can do when working with files.