读取.properties配置文件

时间:2022-01-05 11:59:07

方法1

public  class SSOUtils {

  protected static String URL_LOGIN = "/uas/service/api/login/info";

  static Map getWebserviceUrl = PropertiesUtil.read("webserviceUrl");
  static{
    String url = (String)getWebserviceUrl.get("VERIFICATIONURL");
    URL_LOGIN =url+URL_LOGIN;

 

  }

}

/**
* 读取.properties配置文件的内容至Map中。
* @author luzh
*
*/
public class PropertiesUtil {

/**
* 读取.properties配置文件的内容至Map中
* @param propertiesFile
* @return
*/
public static Map read(String propertiesFile) {
  ResourceBundle rb = ResourceBundle.getBundle(propertiesFile);
  Map map = new HashMap();
  Enumeration enu = rb.getKeys();
  while (enu.hasMoreElements()) {
    Object obj = enu.nextElement();
    Object objv = rb.getObject(obj.toString());
    map.put(obj, objv);
  }
  return map;
}

}

方法2

public abstract class VrmUrl {

  private static String getBASE_URL(){
    Properties prop = new Properties();
    try {
      InputStream in = Class.forName(VrmUrl.class.getName()).getResourceAsStream("/webserviceUrl.properties");
      prop.load(in);
      return prop.getProperty("VRM_URl").trim();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  public static String BASE_URL = getBASE_URL();

  public static String DISPATCHINFO_URL = BASE_URL + "addDispatchInfo";

  public static String ORDERINFO_URL = BASE_URL + "addOrderInfo";

  
}