Search code examples
javafilewriterbufferedwriterwatchservice

Java append text and save file continously


I would like to generate line of words continously and append to a text file. As I am using WatchService, I would want to get the line appended immediately. WatchService require me to do a "Save" before it detect the modification to the file and react accordingly. Is there a way to "Save" after each line is appended?


Solution

  • Use flush() method of your Writer after you write the text to you file.