74.Java异常处理机制

 1 package testDate;
 2 import java.io.FileNotFoundException;
 3 import java.io.FileReader;
 4 import java.io.IOException;
 5 public class TestReadFile {
 6     public static void main(String[] args) {
 7         FileReader reader = null;
 8         try{
 9             reader=new FileReader("d:/a.txt");
10             char c1=(char)reader.read();
11             char c2=(char)reader.read();
12             System.out.println(""+c1+c2);
13         }catch(FileNotFoundException e){
14             e.printStackTrace();
15         }catch(IOException e){
16             e.printStackTrace();
17         }finally{
18             try {
19                 if(reader!=null){
20                     reader.close();
21                 }
22             } catch (IOException e) {
23                 e.printStackTrace();
24             }
25         }
26     }
27 }

posted @ 2017-12-08 11:33  wydxry  阅读(218)  评论(0编辑  收藏  举报
Live2D