读取配置文件的方法

/**
    * @description: 加载properties文件
    * @param  文件路径
    * @return Properties 对象
    * @author douyumeng
     * @throws IOException,FileNotFoundException 
    */ 
    public static Properties getProperties(String path){
        BaseUtil bu = new BaseUtil();
        String classpath = bu.getWebClassesPath();
        path=classpath+path;
        Properties prop = new Properties();
        try {   
            InputStream in = new FileInputStream(new File(path));  
            prop.load(in);    
         } catch (Exception e) {
              e.printStackTrace();
              return null;
         }    
        return prop;
    }

使用:

增加了size-config.properties文件
读取方法为:BaseUtil.getProperties("com/tshn/config/attachment/size-config.properties").getProperty("yourkey")

posted @ 2012-08-17 08:58  lcuzhanglei  阅读(152)  评论(0编辑  收藏  举报