从properties文件获取配置信息。
PropsUtil.java
PropsUtil.java
import java.io.IOException;
import java.util.Properties;
public class PropsUtil {
/**一个property文件的内存对象*/
private static Properties pops = null;
/**
* <li>实例化一个Properties对象
*/
static {
pops = new Properties();
try {
pops.load(PropsUtil.class.getResourceAsStream("/com/test/resource/resource.properties/*此处写properties路径*/"));
} catch (IOException e) {
e.printStackTrace();
}
}
/**
*
* @param key
* @return key所对应的value
*/
public static String getStringPro(String key) {
return pops.getProperty(key);
}
/**
*
* @param key
* @return 得到key所对应的int value
*/
public static int getIntPro(String key){
return Integer.valueOf(pops.getProperty(key));
}
public static boolean getBooleanPro(String key){
return Boolean.valueOf(pops.getProperty(key));
}
}