Java - 什么引发IOException [英] Java - What throws an IOException

查看:120
本文介绍了Java - 什么引发IOException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.io.IOException 似乎是最常见的异常类型,巧合的是,它似乎也是最模糊的。每当使用套接字,文件和c写入时,我都会看到 throws IOException 。然而,我从来没有对我开枪,所以我想知道这是什么原因引发了这个例外。该文档对解释发生了什么不是很有帮助:

java.io.IOException seems to be the most common type of exception, coincidentally, it seems to also be the most ambiguous. I keep seeing the throws IOException whenever writing with sockets, files, &c. I've never actually had one fired on me, however, so I'm wondering what it is that is supposed to fire the exception. The documentation isn't very helpful in explaining what's going on:


表示发生了某种类型的I / O异常。这个类是由失败或中断的I / O操作产生的一般异常类。

Signals that an I/O exception of some sort has occurred. This class is the general class of exceptions produced by failed or interrupted I/O operations.

有人可以解释一些IOException将被抛出,或者它应该如何被利用。

Can someone please explain some instances where an IOException would be thrown, or how it's supposed to be utilized.

推荐答案

假设你是:


  1. 阅读网络文件并断开连接。

  2. 读取不再可用的本地文件。

  3. 使用一些流读取数据,其他一些进程关闭流。

  4. 尝试读/写文件,但没有权限。

  5. 尝试写入文件,但磁盘空间不再可用。

  1. Reading a network file and got disconnected.
  2. Reading a local file that was no longer available.
  3. Using some stream to read data and some other process closed the stream.
  4. Trying to read/write a file but don't have permission.
  5. Trying to write to a file but disk space was no longer available.

有更多的例子,但这些是我经验中最常见的。

There are many more examples, but these are the most common, in my experience.

这篇关于Java - 什么引发IOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆