1. Resource leaks under normal circumstances
FileOutputStream fos = newfileoutputstream (New File ("test.txt"));
...
The FOS is no longer closed.
2. Resource leaks in exceptional circumstances
1)
FileOutputStream fos = newfileoutputstream (New File ("test.txt"));
Fos.write (7); Write () has an exception, causing fos.close () to not be executed.
Fos.close ();
2)
FileOutputStream fos1 = Newfileoutputstream (New File ("Test1.txt"));
FileOutputStream Fos2 = Newfileoutputstream (New File ("Test2.txt"));
Fos1.close (); Close () has an exception, causing Fos2 to have no close. --close () calls flush (), so it is possible to throw an exception.
Fos2.close ();
The Try/catch anomaly mechanism of Java is a checked exception mechanism. The purpose is to report errors that occur while the program is executing. When an exception occurs, the program cannot continue execution and exits. Under such circumstances, it is trifles to explore the "resource leakage", which is of little significance.