package com.throwsss;

 import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream; /**
* IO异常 的处理
* @author Administrator
*用 throw new RuntimeException(e);方法
*/
class Read{
public static void readTest(){
File file = new File("D://aa.txt");
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
byte[] bs = new byte[1024];
int length = 0;
while((length = inputStream.read(bs)) != -1){
String str = new String(bs,0,length);
System.out.println(str);
}
} catch (FileNotFoundException e) {
//e.printStackTrace();
throw new RuntimeException(e);
} catch (IOException e){
//e.printStackTrace();
throw new RuntimeException(e);
} finally{
if(inputStream != null){
try {
inputStream.close();
System.out.println("文件釋放成功");
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println("文件释放失败");
throw new RuntimeException(e); }
}
} }
}
public class Throwss { public static void main(String[] args) {
// TODO Auto-generated method stub Read read = new Read();
read.readTest();
} }

IO异常 的处理的更多相关文章

  1. 分享一个异步任务在遇到IO异常时支持递归回调的辅助方法

    public void TryAsyncActionRecursively<TAsyncResult>( string asyncActionName, Func<Task<T ...

  2. java.sql.SQLException: Io 异常: Connection reset

    当数据库连接池中的连接被创建而长时间不使用的情况下,该连接会自动回收并失效,但客户端并不知道,在进行数据库操作时仍然使用的是无效的数据库连接,这样,就导致客户端程序报“ java.sql.SQLExc ...

  3. java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=186646784)(ERR=12505)(ERR

    dbc 链接orcal出错 java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=186646784)( ...

  4. 数据库连接报错之IO异常(The Network Adapter could not establish the connection)

    Io 异常: The Network Adapter could not establish the connection 有以下四个原因: 1.oracle配置 listener.ora 和tnsn ...

  5. spring+ibatis问题1—— 程序报错:java.sql.SQLException: Io 异常: Connection reset by peer, socket write error; ”或“java.sql.SQLException 关闭的连接”异常

    转自:http://blog.sina.com.cn/s/blog_1549fb0710102whz2.html spring+ibatis程序测试时报错:java.sql.SQLException: ...

  6. Io 异常: The Network Adapter could not establish the connection

    新接触一个项目,导入源码,在本地启动的时候后台报了一个错误: Could not discover the dialect to use. java.sql.SQLException: Io 异常: ...

  7. IO 异常:The Network Adapter could not establish the connection 怎么解决

    IO 异常:The Network Adapter could not establish the connection 怎么解决

  8. Flutter采坑之路 用真机跑起来的时候提示 initGradle失败,IO异常,downloading Gradle-4.6-all.zip失败

    这个异常就是Gradle下载异常,进而下面会提示一行IO异常 我这里的原因就是Gradle对应的4.6-all版本下载不下来(一般情况下确实很难下载下来) 所以在正常AS工程呢,我们选择一下Gradl ...

  9. linux xfs的一次io异常导致的crash

    returned. [ blocked seconds.----这个默认是120,该环境上是被人为设置1200 [8556407.425653] "echo 0 > /proc/sys ...

  10. Android HttpURLConnection.connect找不到源 HttpURLConnection连接失败 HttpURLConnection.connect IO异常 解决办法

    Android HttpURLConnection.connect找不到源  HttpURLConnection连接失败 HttpURLConnection.connect IO异常 解决办法 以下代 ...

随机推荐

  1. 20155207王雪纯 Exp2 后门原理与实践

    20155207王雪纯 Exp2 后门原理与实践 实验步骤 一.windows获取Linux shell Windows:使用 ipconfig 命令查看当前机器IP地址. 进入ncat所在文件地址, ...

  2. 2017-2018-1 20155336 《信息安全系统设计基础》加分作业:实现mypwd

    2017-2018-1 20155336 <信息安全系统设计基础>加分作业:实现mypwd 什么是PWD? 用man pwd查看: 用于打印当前工作目录的工作路径 1.命令格式:pwd[选 ...

  3. mfc 异常机制

    异常 抛出异常 捕获异常 一.异常 迄今为止,我们处理程序中的错误一般都是用if语句测试某个表达式,然后处理错误的特定义代码. C++异常机制使用了三个新的关键字 (SEH(结构化异常处理)) try ...

  4. SP1716 GSS3 - Can you answer these queries III

    题面 题解 相信大家写过的传统做法像这样:(这段代码蒯自Karry5307的题解) struct SegmentTree{ ll l,r,prefix,suffix,sum,maxn; }; //.. ...

  5. BZOJ2439【中山市选2011】序列

    题面 题解 设$f[i]$表示将$[1,i]$修改为递增的最小代价, $g[i]$表示将$[i,n]$修改为递减的最小代价. $L[i]$表示将$[1,i]$修改为倒$\text V$的代价 $$ \ ...

  6. Asp.net中使用缓存(cache)

    做了一个时间优化的项目,目的就是缩短程序过程中的时间花费,最后发现了asp.net和asp.net core 中都有缓存工具来进行缓存,以加快访问速度. 找了官方demo来进行分析: ObjectCa ...

  7. POJ-2299 Ultra-QuickSort (树状数组)

    题目链接:Ultra-QuickSort 题意: 给出了一个序列,序列中有n个数,现在每次操作能交换相邻的两个数,要求操作几次可以将这个序列转换为一个从小到大排序的序列. 题解: 我的解法是先把所有的 ...

  8. directive指令二 require:'^ngModel'

    本章主要是讲指令与ngModel的交互. 在angular有一个内置指令叫ngModel,它是angular用来处理表单的最重要的指令.在源码中,页面上的model值的格式化.解析.验证都是由ngMo ...

  9. nginx遇到的配置问题

    配置的例子如下: server { listen ; server_name localhost; #kzjtrans-web location /kzjtrans-web/ { proxy_pass ...

  10. AndroidStudio更改包名

    最近开发一个项目 和以前开发的某一个功能类似 不想再重新搭建界面 从零开始去写... 就想把原来的项目copy一份 但是这样的话安装在手机中会把原来的项目覆盖掉 这是因为它们的applicationI ...