IO异常 的处理 test
2015-08-04 23:31
176 查看
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(); } }
相关文章推荐
- 初窥Python(二)——修改pip源
- 【JAVA】final修饰Field
- OC基础学习第一天
- 快速排序
- 欧拉回路及其构造
- linux下shell脚本执行jar文件
- 加快mysql导入导出速度
- Ruby
- BeanUtils.populate的作用 !
- 一个java老菜鸟的而立之感(一)
- ps学习笔记二(矢量图)
- 【罗辑思维】物种战争
- UEditor的配置和使用(单独图片与文件上传)
- 背包算法解决一道华为面试题
- Spring 中设置依赖注入
- 对给定字符串,取出它的子字符串,并把子字符串按照长度排序
- Linux下Weblogic 11g R1安装和配置
- Leetcode: Count Primes
- 阻塞队列自定义实现 in Java
- 数组