Java读取property文件
public static Properties loadProps(String fileName) {
Properties properties = null;
InputStream inputStream = null;
try {
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
if (inputStream == null) {
throw new FileNotFoundException(fileName);
}
properties = new Properties();
properties.load(inputStream);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
closeStream(inputStream);
}
return properties;
}
private static void closeStream(InputStream inputStream) {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
作者:iBrake
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

浙公网安备 33010602011771号