zoukankan      html  css  js  c++  java
  • 读取.properties配置文件

    方法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";

      
    }

  • 相关阅读:
    堆和栈的区别(转)
    conversion to dalvik format failed with error 1的解决办法
    eclipse最实用快捷键
    java socket编程(转)
    Android 面试总结
    Android横竖屏总结(转)
    Android布局文件属性笔记(转)
    常用数据结构有哪些(转)
    经常用到的Eclipse快捷键(转)
    url编码转换
  • 原文地址:https://www.cnblogs.com/lizihao/p/6008517.html
Copyright © 2011-2022 走看看