Always close resources with the finally block:
acquire(); try { use(); } finally { release(); }
Your only resource here is FileOutputStream , so it is the only one that really needs to be closed. If the PrintWriter constructor was supposed to be thrown, you really should free the FileOutputStream anyway, which excludes just closing the PrintWriter .
Notice you really want flush PrintWriter . This should only be done in a case other than exception, and therefore ultimately not required.
source share