properties 在编译以后读取不到
ClassLoader classLoader = Thread.currentThrea().getContextClassLoader();
InputStream in = classLoader.getResourceAsStream("[u]/[/u]const.properties");
Properties prt = new Properties();
try {
prt.load(in);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
properties 文件放在src下 后来在文件名前加了个“/”就能读取了
"/****"表示根目录
ClassLoader classLoader = Thread.currentThrea().getContextClassLoader();
InputStream in = classLoader.getResourceAsStream("[u]/[/u]const.properties");
Properties prt = new Properties();
try {
prt.load(in);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
properties 文件放在src下 后来在文件名前加了个“/”就能读取了
"/****"表示根目录
本文介绍了一种在Java中加载properties配置文件时遇到的问题及解决方案。通过使用正确的路径指定方式,能够成功地利用ClassLoader从项目的根目录加载配置文件。

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



