properties属性加载

来源:互联网 发布:java单例模式 实际应用 编辑:程序博客网 时间:2024/05/04 10:05

package com.li.utils;

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

public class Url {
 private static Properties properties = new Properties();

 static {
  try {
   properties.load(Url.class.getClassLoader().getResourceAsStream(
     "url.properties"));
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

 public static String getValue(String key) {
  return properties.getProperty(key);

 }
}

 

 

 

该文件位于根目录下url.properties