13.07.2015 Views

I/O Fundamentals

I/O Fundamentals

I/O Fundamentals

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Java Input and OutputThe java.io ExceptionsIn some cases it may be perfectly appropriate to "pass the buck" to the caller byadding a throws clause. In other cases it's more appropriate to handle theexception and shield the caller from ever knowing something went wrong. This isstrictly up to your application design.The following is a list of all exceptions defined in package java.io, with a briefdescription of each. A few of these exceptions will be covered in detail after thissection.A problem occurred while converting a char toone or more bytes, or vice-versa. This canoccur in:CharConversionExceptionOutputStreamWriter(note that FileWriter subclassesOutputStreamWriter!)Converting between byte[] to a String (ineither direction)EOFExceptionFileNotFoundExceptionInterruptedIOExceptionThe end of a stream was unexpectedly reached.Normally hitting "end-of-file" is signaled by aspecial value, such as a -1 return from a read()call. However, some streams, likeDataInputStream might hit end-of-file in themiddle of reading a multi-byte quantity, such asa call to readInt(). In cases like that,EOFException is thrown.A file specified in a constructor toFileInputStream, FileOutputStream,FileReader, FileWriter, orRandomAccessFile does not exist.Note that this could also mean that the file wasbeing opened in the wrong mode, for example,trying to open a read-only file for write access.An I/O operation was halted because the threadperforming the operation was terminated.© 1996-2003 jGuru.com. All Rights Reserved. Java Input and Output -57

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!