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. 解决Xcode 7 http无法使用的问题

    在info.plist文件中添加 <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbit ...

  2. ORM增删改查(django)

    单表操作: 一.添加 (1)方式一 from  mysite.models  import * def  add(request): book= Book(name="python" ...

  3. UOJ#34. 多项式乘法(NTT)

    这是一道模板题. 给你两个多项式,请输出乘起来后的多项式. 输入格式 第一行两个整数 nn 和 mm,分别表示两个多项式的次数. 第二行 n+1n+1 个整数,表示第一个多项式的 00 到 nn 次项 ...

  4. jQuery----五星好评实现

    在美团.淘宝.京东等网页上,有许多商品.服务评价页面,五星好评功能很常见,本文利用jQuery实现五星好评功能. 案例图片:                                       ...

  5. POJ 1235 Machine Schedule 【二分图】

    这道题考察对最小点覆盖的理解. 做法: 对于一个作业,它需要A的a模式和B的b模式,那么可以从a模式向b模式连一条边:可以感性的理解为每一条边就是一个作业,需要求得有多少个模式可以覆盖所有的边,也就是 ...

  6. JavaWeb总结(三)

    什么是Servelt - 是运行在Web服务器或应用服务器上的Java程序 - 在Web上创建动态内容的有效而强大的解决方案 - 由容器来管理生命周期与Web服务器交互 Servlet规范的组成 Ja ...

  7. PostreSQL崩溃试验全记录

    磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面: PostgreSQL基础知识与基本操作索引页     回到顶级页面:PostgreSQL索引页 [作者 高健@博客园  luckyjackg ...

  8. django学习笔记(4)

    Part 4: Forms and generic views ====> Write a simple form$ edit polls\templates\polls\detail.html ...

  9. 4515: [Sdoi2016]游戏

    4515: [Sdoi2016]游戏 链接 分析: 树链剖分 + 超哥线段树.注意细节. 代码: #include<cstdio> #include<algorithm> #i ...

  10. while、for循环控制之if、else

    if # score=99 # if score>90: # print('优秀') # elif score<60: # print('不及格') # else: # print('良好 ...