获取Porperties通用类GetProInfo

来源:互联网 发布:软件系统部署方案 编辑:程序博客网 时间:2024/05/06 11:23

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


public class GetProInfo {
 public static void main(String args[]){
  System.out.println(new GetProInfo().getProInfo("endpoint"));
 }
  public String getProInfo(String tag) {
   Properties pro=new Properties(); 
   FileInputStream profis=null;
   String path=" ";
   try {
    path=System.getenv("PRO_PATH"); // get system envirenment
    profis=new FileInputStream(path+"//dean.properties");
    pro.load(profis);
    //pro.load(GetProInfo.class.getClassLoader().getResourceAsStream("dean.properties"));
    String info=pro.getProperty(tag);
    return info;
   } catch (Exception e) {
    e.printStackTrace();
    return null;
   }finally{
    if(profis!=null){
     try {
      profis.close();
     } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
    }
   }
  }
 
}

 

原创粉丝点击