package com.throwsss;

 import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; class Picture{
public static void readWrite(){
File file = new File("D://abc.jpg");
File file2 = new File("F://abc.jpg");
InputStream inputStream = null;
FileOutputStream fileOutputStream = null;
try {
inputStream = new FileInputStream(file);
fileOutputStream = new FileOutputStream(file2);
byte[] bs = new byte[1024];
int length = 0;
try {
while((length = inputStream.read(bs))!=-1){
fileOutputStream.write(bs, 0, length);
}
} catch (IOException e) {
// TODO Auto-generated catch block
throw new RuntimeException(e);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
throw new RuntimeException(e);
}finally{
if(fileOutputStream != null){
try {
fileOutputStream.close();
System.out.println("关闭输出流资源成功...");
} catch (IOException e) {
System.out.println("关闭输出流资源失败...");
throw new RuntimeException(e);
}finally{
if(inputStream != null){
try {
inputStream.close();
System.out.println("关闭输入流对象成功...");
} catch (IOException e) {
System.out.println("关闭输入流对象失敗...");
throw new RuntimeException(e);
}
}
}
}
} }
} public class Throwtest { public static void main(String[] args) {
// TODO Auto-generated method stub Picture picture = new Picture();
picture.readWrite();
} }

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

  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. GoogleTest初探(1)

    此篇主要了解一下GoogleTest中的断言. 总的来说,GoogleTest中的断言分为两大类:EXPECT_*和ASSERT_*,这两者在测试成功或失败后均会给出测试报告,区别是前者在测试失败后会 ...

  2. mysql where语句多条件查询是and和or联合使用bug

    公司项目中有段功能是全局搜索框和下拉列表的联合查询,在联调开发中发现单独用下拉查询是正确的,单独用全局搜索框也是正确的,测试发现是sql语法有问题. 问题截图: 出现问题的核心还是在于搜索框是用于多个 ...

  3. Rails 自定义验证的错误信息

    Active Record 验证辅助方法的默认错误消息都是英文,为了提高用户体验,有时候我们经常会被要求按特定的文本展示错误信息.此时有两种实现方式. 1. 直接在:message添加文案 class ...

  4. 认识node

    node是一个基于Chrome V8引擎的ECMAScript运行环境,使用了ECMAScript语法规范.有了node之后,js文件就能运行在服务器端了,也可以用来创建web服务器. node的主要 ...

  5. myeclipse(eclipse)IDE配置

    1.更换JDK8 2.更换低版本的eclipse试试 其他方法暂时没想到 一.设置编码与字体 工作空间编码设置:window->perferences->General->words ...

  6. python 线程及线程池

    一.多线程 import threading from time import ctime,sleep def music(func): for i in range(2): print(" ...

  7. angularJs中缓存数据,免去重复发起请求的几种写法

    带缓存处理的两种写法 过程:点击button触发load()方法,请求数据成后显示到页面中.如果已经请求过则从缓存中读取. 在线浏览 写法1: function demo(){ if (demo.ca ...

  8. 团队合作开发git冲突解决方案 Intellij IDEA

    https://blog.csdn.net/antony9118/article/details/52524873 注:因为我使用的是 idea 2018.1.2的版本,所以在操作上有些变化 将某些操 ...

  9. IT程序员每天的困扰:这TM为啥不可以?这TM也行?

    如果有对 Python 感兴趣的程序员,可以加我们小助手的QQ:979950755 会免费送 Python 的视频教程噢! 随着IT互联网对社会的影响越来越重要,关乎人类的未来发展进程.所以现在很多媒 ...

  10. 用xpo实现dc技术的关键点-XPO是如何处理接口类型与真实类型的对应关系的

    https://www.devexpress.com/Support/Center/Question/Details/Q487000/xpodatamodel-and-model-interfaces ...