Java之IO异常处理

来源:互联网 发布:flyme数据同步助手 编辑:程序博客网 时间:2024/05/20 16:42
import java.io.* ;class FileWriterDemo2{public static void main(String args[]){         FileWriter fw = null ;//防止无法执行finally中的close方法         try{            fw = new FileWriter("demo2.txt") ;            fw.write("abcde") ;         }catch(IOException e){               System.out.println(e.toString()) ;         }finally{             //捕获close方法的异常          try{          //防止fw没有被实例化          if(fw!=null){          fw.close() ;          }          }catch(IOException e){          System.out.println(e.toString()) ;          }         }}}

0 0
原创粉丝点击