I'm studying for OCP exam these classes I/O:
OutputStream subclasses:
- FileOutputStream
- BufferedOutputStream
- DataOutputStream
- PrintStream (I see its methods write() don't throw exceptions)
Writer subclasses:
- FileWriter
- BufferedWriter
- PrintWriter (I see its methods write() don't throw exceptions)
Reader subclasses:
- FileReader
- BufferedReader
InputStream subclasses:
- BufferedInputStream
- FilterInputStream
- ObjectInputStream
My question: For the main methods read and write (with different signatures), when does each of these classes throw the IOException? In the javadoc there is only a phrase:
IOException - if an I/O error occurs
without an explanation about the cases.
I know this (I don't know if these are correct):
FileOutputStream throws java.io.FileNotFoundException if the file doesn't exist. This class, infact, doesn't create a file;
FileWriter throws java.io.FileNotFoundException if the file doesn't exist. This class infact, doesn't create a file;
BufferedReader throws java.nio.file.NoSuchFileException (subclass of IOException), if file doesn't exist;
FileInputStream throws java.io.FileNotFoundException if the file doesn't exist.
Thanks a lot!
A.