分享

Properties读取配置文件中的属性值

 嗖叭鸟 2014-01-22
import java.util.Properties;

import org.apache.log4j.Logger;


public class PropertyReader {
private static Properties props=new Properties();
private final Logger logger = Logger.getLogger(getClass());
   public PropertyReader(){
     loadConfigFile("fileupload.properties");
   }
   public PropertyReader(String fileName){
     loadConfigFile(fileName);
   
   }
private  void loadConfigFile(String fileName) {
try {
java.io.InputStream fis = getClass().getResourceAsStream("/" + fileName);
props.load(fis);
//props.load(new FileInputStream("/"+fileName));
}
catch(Exception e) {
logger.error("load file failed!",e);
}
}
public String getProperty(String key){
return props.getProperty(key);
}
public int size(){
return props.size();
}
public Properties getProperties(){
return props;
}
/**
* @param args
*/
public static void main(String[] args) {
PropertyReader pr = new PropertyReader("config.properties");
String a = pr.getProperty(null+"");
System.out.println(a==null?"":a);

}

}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多