您的位置:首页 > 编程语言 > Java开发

java 读取属性文件里边的键值

2012-03-28 17:17 281 查看
package com.mail.dao;

import java.io.FileInputStream;

import java.io.InputStream;

import java.util.Properties;

public class readProperties {

     //private static Logger log = Logger.getLogger(sd.class);

     private static Properties pros = null;

      private synchronized static void loadInitFile() {

      if (pros == null) {

       pros = new Properties();

      }

      try {

       InputStream inStream =new FileInputStream("D:\\eclipse\\workspace\\submail\\WebContent\\config.properties");

       pros.load(inStream);

       //log.info("Initialize DAOConfig success!");

      } catch (Exception e) {

       //log.error("Loading daoConfig.properties fail!!");

       //log.error(e);

       e.printStackTrace();

      }

     }

     public static String getProperty(String propName) {

      loadInitFile();

      return pros.getProperty(propName);

     }

     public String getemailname(){

         return readProperties.getProperty("mails.emailname");

     }

     public String getpwd(){

         return readProperties.getProperty("mails.pswd");

     }

    public String gethost(){

        return readProperties.getProperty("mails.host");

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息