posts - 97,  comments - 93,  trackbacks - 0

In a project, we can write a class to read the properties.As following,

import java.io.InputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertyReader{
   private static Properties property = null;
  
   static{
      InputSteam stream = null;
      try{
        stream=PropertyReader.class.getResourceAsStream("/resource/properties.properties");
        property = new Properties();
        property.load(stream);
      }catch(IOException e){
          e.printStackTrace();
      }finally{
          if(stream != null){
             try{
                stream.close();
             }catch(IOException e){
                e.printStackTrace();
             }           
          }
      }
   }
   public static String getResource(String key){
     if(property == null){
       return null;// init error;
     }
     
     return property.getProperty(key);
   }
}

posted on 2007-04-05 08:13 wqwqwqwqwq 阅读(465) 评论(0)  编辑  收藏 所属分类: Simple Java

只有注册用户登录后才能发表评论。


网站导航:
 
<2007年4月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345




常用链接

留言簿(10)

随笔分类(95)

随笔档案(97)

文章档案(10)

相册

J2ME技术网站

java技术相关

mess

搜索

  •  

最新评论

阅读排行榜

校园梦网网络电话,中国最优秀的网络电话