Chapter: Java The Complete Reference - The Java Library - Input/Output: Exploring java.io

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail

I/O Exceptions - java.io

Two exceptions play an important role in I/O handling. The first is IOException.

I/O Exceptions

 

Two exceptions play an important role in I/O handling. The first is IOException. As it relates to most of the I/O classes described in this chapter, if an I/O error occurs, an IOException is thrown. In many cases, if a file cannot be opened, a FileNotFoundException is thrown. FileNotFoundException is a subclass of IOException, so both can be caught with a single catch that catches IOException. For brevity, this is the approach used by most of the sample code in this chapter. However, in your own applications, you might find it useful to catch each exception separately.

 

Another exception class that is sometimes important when performing I/O is SecurityException. As explained in Chapter 13, in situations in which a security manager is present, several of the file classes will throw a SecurityException if a security violation occurs when attempting to open a file. By default, applications run via java do not use a security manager. For that reason, the I/O examples in this book do not need to watch for a possible SecurityException. However, applets will use the security manager provided by the browser, and file I/O performed by an applet could generate a SecurityException. In such a case, you will need to handle this exception.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.