Files, sockets, database connections and many streams hold operating system resources that the garbage collector does not release promptly. If you forget to close them you can run out of file handles, leave files locked on Windows, or lose buffered output. The try-with-resources statement is the standard way to guarantee closing.
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 6 more sections, 5 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.