Java 文档有助于了解特定 IOException 的根本原因。
只需查看文档页面中IOException 的直接已知子接口:
ChangedCharSetException, CharacterCodingException, CharConversionException, ClosedChannelException, EOFException, FileLockInterruptionException, FileNotFoundException, FilerException, FileSystemException, HttpRetryException, IIOException, InterruptedByTimeoutException, InterruptedIOException, InvalidPropertiesFormatException, JMXProviderException, JMXServerErrorException, MalformedURLException, ObjectStreamException, ProtocolException, RemoteException, SaslException, SocketException, SSLException, SyncFailedException, UnknownHostException, UnknownServiceException, UnsupportedDataTypeException, UnsupportedEncodingException, UserPrincipalNotFoundException, UTFDataFormatException, ZipException
这些例外中的大多数都是不言自明的。
一些IOExceptions 的根本原因:
EOFException:表示输入期间意外到达文件结尾或流结尾。此异常主要由数据输入流使用,以发出流结束的信号。
SocketException:抛出表示创建或访问 Socket 时出错。
RemoteException:RemoteException 是在执行远程方法调用期间可能发生的许多与通信相关的异常的通用超类。远程接口(扩展 java.rmi.Remote 的接口)的每个方法都必须在其 throws 子句中列出 RemoteException。
UnknownHostException:抛出表示无法确定主机的IP地址(您可能没有连接到Internet)。
MalformedURLException:抛出表示出现了格式错误的 URL。在规范字符串中找不到合法协议,或者无法解析该字符串。