Is there a way to do this?
I'm coding a program that has to iterate for a very long time, and while doing so it is supposed to write to file. I want to close the stream as soon as I terminate the program manually and by doing so, avoid the risk of loosing data because of the unclosed stream. There should be a way of doing this with exception handling, but I'm not sure. Any kind of suggestion is very appreciated!
Thank you
finallyblock. Or, if you're using Java 7, use the try-with-resources block.