IO异常处理方式

/*

 * IO异常处理方式  

*/

import java.io.*;

public class FileWriterDemo2

{

            public static void main(String[] args)

                 {   

                       FileWriter fw=null;  

                       try   

                         {    

                             fw=new FileWriter("demo.txt");    

                             fw.write("abcdefgh");

                        }  

                       catch(IOException e)  

                       {    

                          System.out.println("catch:"+e.toString());  

                        }   

                      finally  

                       {   

                            try   

                                {   

                                 if(fw!=null)     

                                 fw.close();   

                                }   

                               catch(IOException e)   

                              {    

                                  System.out.println(e.toString());   

                               }   

                      }  

             }

}

posted @ 2015-05-08 13:18  冰林  阅读(165)  评论(0编辑  收藏  举报