try {
String url = this.getClass().getResource("").getPath().replaceAll(
"%20", " ");
String path = url.substring(0, url.indexOf("WEB-INF"))
+ "WEB-INF/config/programVersion.properties";
Properties config = new Properties();
config.load(new FileInputStream(path));
System.out.println(config.getProperty("currentVersion"));
} catch (Exception e) {
e.printStackTrace();
}
配置文件放在WEB-INF下的config文件夹下,可任意更改
本文提供了一个Java示例,展示了如何从程序的WEB-INF目录下的config文件夹中读取名为programVersion.properties的配置文件,并打印出其中的currentVersion属性值。
1206

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



