package com.glbk.hec.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* Created by shuai on 2017/4/19.
* 读取配置文件
*/
public class GetProperties {
private static Properties prop = null;
static{
prop = new Properties();
//设置properties文件路径,以src为根路径(config.properties 处于src根目录下)
InputStream in = GetProperties.class.getResourceAsStream("errorCode.properties");
try {
prop.load(in);
} catch (IOException e) {
System.out.println("读取配置文件失败---->>>>----(/src/config.properties)");
e.printStackTrace();
}
}
/**
* 根据传入的KEY获取配置文件中对应的值
* @param key
* @return
*/
public static String getPropertieValue(String key){
String value = "";
value = prop.getProperty(key).trim();
return value;
}
public static void main(String[] args) {
String a="a";
Integer.parseInt(a);
}
}
java代码读取properties文件
最新推荐文章于 2023-03-29 21:06:10 发布