Closing Streams in Java

File handles are scarce, finite resources. You can run out of them if you don’t clean them up properly, just like database connections.

If you’ve written a small program with just one user you can get away with being sloppy and not closing in a finally block.

But if you end up using that idiom in an application that has many users and file handles you might have a problem.

“First we make our habits, then they make us.” I try to apply best practices even when they aren’t necessary.

Leave a Comment