码迷,mamicode.com
首页 > 其他好文 > 详细

处理拷贝图片的异常

时间:2016-12-05 20:10:32      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:int   sys   拷贝   运行   缓冲   stat   input   close   finally   

 1 import java.io.File;
 2 import java.io.FileInputStream;
 3 import java.io.FileNotFoundException;
 4 import java.io.IOException;
 5 
 6 
 7 public class Demo4 {
 8 
 9     /**
10      * @param args
11      */
12     public static void main(String[] args) {
13         getFile();
14       
15     }
16     public static void getFile() {
17         //找到目标文件
18         File  file = new File("C:\\cc\\tt.txt");
19         //建立通道
20         FileInputStream inputStream = null;
21         try {
22             inputStream = new FileInputStream(file);
23             //创建一个缓冲区
24             byte[] b = new byte[1024];
25             try {
26                 int count = inputStream.read(b);
27                 System.out.println(new String(b, 0, count));
28             } catch (IOException e) {
29                 System.out.println("硬盘损坏了,请修理");
30                 throw new RuntimeException(e);
31             }
32         } catch (FileNotFoundException e) {
33             System.out.println("文件不存在");
34             //提示用户有错误要修改
35             //让后面的代码停止运行
36             throw new RuntimeException(e); // 创建一个运行时异常
37         } finally {
38             try {
39                 inputStream.close();
40             } catch (IOException e) {
41                 System.out.println("关闭失败");
42                 throw new RuntimeException(e);
43             }
44         }
45     }
46     
47 
48 }

 

处理拷贝图片的异常

标签:int   sys   拷贝   运行   缓冲   stat   input   close   finally   

原文地址:http://www.cnblogs.com/binzhihua-666/p/6135062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!