java读取properties文件工具

public class PropertiesUtil {

    public static String get(String filePath, String key) {
String val = null;
Properties prop = new Properties();
InputStream in = null;
in = PropertiesUtil.class.getClassLoader().getResourceAsStream(filePath);
try {
prop.load(in);
val = (String) prop.get(key);
} catch (IOException e) {
e.printStackTrace();
}
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
return val;
}
}
上一篇:java虚拟机的类加载机制


下一篇:Java_基础篇(数组的反转)