您的位置:首页 > 运维架构

servlet读取properties文件

2015-12-31 13:51 274 查看
根据properties所在的位置不同,有不同的读法:

(1)如果是在src下面:

InputStream in=this.getclass().getResourceAsStream("/db.properties");

(2)如果是在webcontent目录下面:

inputStream in=this.getServletContext().getResourceAsStream("/db.properties");

Properties prop=new Properties();

prop.load(in);

String user=prop.getProperty("user");

System.out.println(user);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: