title: Continuously write to file in Java efficiently
body: <p>I have a program that's generating a bunch of output I want to to save to a text file. I don't necessarily know when the program is going to end, and I want to have as little impact on performance as possible. Right now I am buffering my lines into a <code>Deque</code>, then dumping that entire <code>Deque</code> into the file every 100 lines (number was arbitrary). I currently using the <code>Files.write()</code> method. </p>
  
  <p>I would ideally like to open the file when the program begins and close the file when the program ends, but I don't know when the program is going to end, so I might fail to close the file. Is that even an issue? Should I do the buffering myself with the <code>Deque</code>, or should I use <code>BufferedWriter</code> or something else similar?</p>