IO异常 的处理
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异常 的处理的更多相关文章
- 分享一个异步任务在遇到IO异常时支持递归回调的辅助方法
public void TryAsyncActionRecursively<TAsyncResult>( string asyncActionName, Func<Task<T ...
- java.sql.SQLException: Io 异常: Connection reset
当数据库连接池中的连接被创建而长时间不使用的情况下,该连接会自动回收并失效,但客户端并不知道,在进行数据库操作时仍然使用的是无效的数据库连接,这样,就导致客户端程序报“ java.sql.SQLExc ...
- 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)( ...
- 数据库连接报错之IO异常(The Network Adapter could not establish the connection)
Io 异常: The Network Adapter could not establish the connection 有以下四个原因: 1.oracle配置 listener.ora 和tnsn ...
- 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: ...
- Io 异常: The Network Adapter could not establish the connection
新接触一个项目,导入源码,在本地启动的时候后台报了一个错误: Could not discover the dialect to use. java.sql.SQLException: Io 异常: ...
- IO 异常:The Network Adapter could not establish the connection 怎么解决
IO 异常:The Network Adapter could not establish the connection 怎么解决
- Flutter采坑之路 用真机跑起来的时候提示 initGradle失败,IO异常,downloading Gradle-4.6-all.zip失败
这个异常就是Gradle下载异常,进而下面会提示一行IO异常 我这里的原因就是Gradle对应的4.6-all版本下载不下来(一般情况下确实很难下载下来) 所以在正常AS工程呢,我们选择一下Gradl ...
- linux xfs的一次io异常导致的crash
returned. [ blocked seconds.----这个默认是120,该环境上是被人为设置1200 [8556407.425653] "echo 0 > /proc/sys ...
- Android HttpURLConnection.connect找不到源 HttpURLConnection连接失败 HttpURLConnection.connect IO异常 解决办法
Android HttpURLConnection.connect找不到源 HttpURLConnection连接失败 HttpURLConnection.connect IO异常 解决办法 以下代 ...
随机推荐
- 如何取得SharePoint Timer Job的历史成功数和失败数,并按照日期计算排列
[问题]. 如何取得SharePoint Timer Job的历史成功数和失败数,并按照日期计算排列 [分析] 管理中心只是罗列了所有job的历史和上一次是否成功,没有关于成功和失败的统计数据 [解决 ...
- jQuery,js如何扩展自定义方法
(jQuery.fn.myMethod=function () { alert('myMethod'); }) (function ($) { $.fn.extend({ myMethod : fun ...
- 前端经典面试题:如何理解 HTML 语义化?
本文最初于 2018-09-21 发布于 知乎 ,后在 <重学前端> 专栏的学习中,重新复习整理,发布于 Github 上,并计划写一系列前端学习相关的文章.欢迎 star . HTML ...
- Windows 视频Directshow开发介绍
在Windows平台上实现一个文件播放器有什么好的开发库和方案呢?方案有很多,比如基于FFmpeg,VLC的插件,mplayer,Directshow.用FFmpeg来实现文件格式解析.分离视频音频流 ...
- 用脚本js把结果转化为固定小数位的形式
function roundTo(base,precision) { var m=Math.pow(10,precision); var a=Math.round(base * m) / m; ret ...
- C 共享内存封装
引言 - 背景 2016 年写过一篇关于 linux 共享内存 shm api 扫盲文. C扩展 从共享内存shm到memcache外部内存 比较简单. 没有深入分析(能力有限, 也深入分析不了). ...
- https确实加密了。 抓包是一个中间人攻击过程
https加密了为什么抓包还是明文 有客户已经正确部署了SSL证书,但是向我们提出了这个问题:我今天采用抓包工具进行抓包,但是我发现数据没有加密,请问是怎么回事?那采用证书加密有什么用?是不是很轻易的 ...
- python基础学习1-装饰器在登陆模块应用
LOGIN_USER ={"islogin":False} def outer(func): def inner(*args,**kwargs): if LOGIN_USER[&q ...
- windows7 64位机上安装配置CUDA7.5(或8.0)+cudnn5.0操作步骤
按照官网文档 http://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html#axzz4TpI4c8v ...
- SpringCloud-初识微服务(一)
前言 本篇文章简单介绍一下什么是微服务.微服务的优点.SpringCloud的微服务架构核心组件选型等: 一.什么是微服务? 微服务的提出者Martin Fowler是这样描述微服务的(原文:http ...