Java is used try-catch-finally exception handling IO streams

We use the exception try-catch-finally receive IO streams
finally the last step is performed, ideally suited to close the last store closed IO streams, and programming we can not arbitrarily throw an exception, an exception must be processed.

Try-catch-finally written from the try-catch ideas are as follows:

We need to close finally in place, therefore:

Fos is defined in the try in the finally clause can not use, so we define fos outside trycatch:

fos get out as partial traverse the first assignment, so fos assignment to null:

fos meaning assignment is null points to a null byte stream, which is obviously null pointer exception, thus:

close () method itself is a compile-time exception handling try-catch needs.

finally:

Guess you like

Origin www.cnblogs.com/maomaodesu/p/11918750.html