[英]Exception for classes I/O
I'm studying for OCP exam these classes I/O: 我正在为以下课程I / O学习OCP考试:
OutputStream subclasses: OutputStream子类:
Writer subclasses: 作家子类:
Reader subclasses: 读者子类:
InputStream subclasses: InputStream子类:
My question: For the main methods read and write (with different signatures), when does each of these classes throw the IOException? 我的问题:对于主要的读写方法(具有不同的签名),这些类中的每一个何时会引发IOException? In the javadoc there is only a phrase: 在javadoc中只有一个短语:
IOException - if an I/O error occurs IOException-如果发生I / O错误
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. 如果文件不存在,则FileOutputStream引发java.io.FileNotFoundException。 This class, infact, doesn't create a file; 实际上,此类不会创建文件。
FileWriter throws java.io.FileNotFoundException if the file doesn't exist. 如果文件不存在,则FileWriter引发java.io.FileNotFoundException。 This class infact, doesn't create a file; 此类实际上并没有创建文件;
BufferedReader throws java.nio.file.NoSuchFileException (subclass of IOException), if file doesn't exist; 如果文件不存在,则BufferedReader抛出java.nio.file.NoSuchFileException(IOException的子类);否则,抛出Exception。
FileInputStream throws java.io.FileNotFoundException if the file doesn't exist. 如果文件不存在,则FileInputStream引发java.io.FileNotFoundException。
Thanks a lot! 非常感谢!
A. 一种。
If you google the API documentation for the class, generally the Javadocs will give an explanation of what exceptions are thrown in what circumstances, eg for FileWriter 如果您搜索该类的API文档,通常Javadocs会解释在什么情况下会抛出哪些异常,例如FileWriter
https://docs.oracle.com/javase/7/docs/api/java/io/FileWriter.html https://docs.oracle.com/javase/7/docs/api/java/io/FileWriter.html
An I/O exception is thrown by any of these classes when they encounter a problem during execution. 当这些类在执行过程中遇到问题时,它们会抛出I / O异常。 The file output streams can throw an exception if : 如果出现以下情况,文件输出流可能会引发异常:
The input streams usually throws exception if : 如果以下情况,输入流通常会引发异常:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.