idea中tomcat下读取资源文件的路径,资源文件放在web下面
程序员文章站
2022-04-30 13:58:22
...
Properties properties = new Properties();
try {
// System.out.println("开始try...");
InputStream is = this.getServletContext().getResourceAsStream("/db.properties");
properties.load(is);
// System.out.println("读取文件位置没有报错..");
} catch (Exception e) {
// e.printStackTrace();
System.out.println("有问题..");
} finally {
System.out.println("finally...");
}
System.out.println(properties);
String driveClassName = properties.getProperty("driveClassName");
String url = properties.getProperty("url");
System.out.println(driveClassName);
System.out.println(url);
上一篇: Linux组管理与权限管理