protected Properties load() {
try {
Properties prop = new Properties();
String path = "prop/conf.properties";
String os = System.getProperty("os.name");
if (os.toLowerCase().startsWith("win")) {
path = "/src/prop/conf.properties";
}
InputStream in = new FileInputStream(System.getProperty("user.dir") + File.separator + path);
prop.load(in);//属性文件将该流加入的可被读取的属性中
return prop;
} catch (Exception ex) {
log.error("加载配置文件异常,系统over@@", ex);
System.exit(0);
}
return null;
}
本文介绍了一种使用Java Properties类来加载配置文件的方法。通过判断操作系统类型来确定配置文件路径,并利用FileInputStream读取文件内容。如果加载过程中出现异常,则记录错误并终止程序。
9668

被折叠的 条评论
为什么被折叠?



