/**
* 在当前类路径或类的根路径下查找文件
* @param fileName
* @return Properties prop
*/
public static Properties load(String fileName) {
Properties prop = new Properties();
InputStream is = ZhPropertiesUtil.class.getResourceAsStream(fileName);
try {
if(is==null){//根路径下去试
String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
is =new FileInputStream(path+"/"+fileName);
}
prop.load(is);
} catch (Exception e) {
//throw new RuntimeException("导入属性文件出错!", e);
System.out.println("导入属性文件出错!/n"+e.toString());
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return prop;
}
JAVA读配置文件--在类的根路径及当前类的路径下
最新推荐文章于 2022-10-04 19:40:14 发布