I have already created a file with information, if I need to add a couple more lines to it, then according to the documentation it says so

When the output file is open, any previously existing file with the same name is destroyed.

So if you need to add lines to an existing file, then you need to open the input stream, write everything from the existing file somewhere to the buffer, then add to it what you need and write a new file?

Or is there a smoother solution?

    1 answer 1

    You may have noticed that FileOutputStream has an append boolean extension.

    True if the file is opened for append.

    true if the file is open for adding.

    try (FileOutputStream output = new FileOutputStream(file, true)) { output.write(data); } 

    ...

     FileOutputStream output = new FileOutputStream(file, true); try { output.write(data); } finally { output.close(); } 
    • 3
      The Boolean value true translated into Russian as истина . The translation is правда - incorrect. - Pavel Mayorov
    • one
      The point is not about the translation, but you are right, this translation is not correct. - Shwarz Andrei