zoukankan      html  css  js  c++  java
  • try catch finally 关闭流标准的写法

    平常开发中,都知道要在finlly里关闭流,但是有时finlly里代码不当,会引起另外的异常。 
    以下是看struts2源代码看到的,随手记录下。 
    有两点注意: 
    (1)判断流是否为空。 
    (2)filly里要捕获异常 

    Java代码  收藏代码
      1.         InputStream in = null;  
      2.         try {  
      3.             in = settingsUrl.openStream();  
      4.             settings.load(in);  
      5.         } catch (IOException e) {  
      6.             throw new StrutsException("Could not load " + name + ".properties:"  
      7.                     + e, e);  
      8.         } finally {  
      9.             if (in != null) {  
      10.                 try {  
      11.                     in.close();  
      12.                 } catch (IOException io) {  
      13. //log  
      14.                 }  
      15.             }  
      16.         }  
  • 相关阅读:
    选择排序
    散列冲突解决方案
    string stringbuffer StringBuilder
    java关键字
    Vector
    What is the difference between book depreciation and tax depreciation?
    Type of Asset Books in Oracle Fixed Assets
    questions
    Oracle Express 11g
    iot
  • 原文地址:https://www.cnblogs.com/xujanus/p/5378363.html
Copyright © 2011-2022 走看看