IOException
is a type of exception in Java that is thrown when an input/output operation encounters a failure. It is a checked exception, which means that it must be handled or declared in the method where it occurs.
IOException
is the base class for a variety of exceptions that are thrown while accessing data from files, directories, and streams. Some common exception classes that are derived from the IOException
base class include EndOfStreamException
, FileNotFoundException
, and DirectoryNotFoundException
.
Instances where an IOException
would be thrown include attempting to access a file that does not exist at the specified location. Other examples include writing with sockets, files, and working with network sockets or other system resources.
The IOException
class has several constructors that can be used to create an instance of the exception with a specified detail message and cause. The ioException()
method of the Scanner
class can be used to get the IOException
last thrown by the scanners readable.