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 Deque, then dumping that entire Deque into the file every 100 lines (number was arbitrary). I currently using the Files.write() method.
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 Deque, or should I use BufferedWriter or something else similar?