使用servletContext读取资源文件
2017-04-09 20:26
351 查看
//读取webroot目录下的资源
InputStream in = this.getServletContext().getResourceAsStream("/db.properties");
System.out.println(in);
//获取web资源的绝对路径
String path = this.getServletContext().getRealPath("/WEB-INF/classes/db.properties");
FileInputStream in = new FileInputStream(path);
Properties prop = new Properties();
prop.load(in);
String driver = prop.getProperty("driver");
String url = prop.getProperty("url");
String username = prop.getProperty("username");
String password = prop.getProperty("password");
//读取web工程中资源文件
InputStream in = this.getServletContext().getResourceAsStream("/WEB-INF/classes/db.properties");
Properties prop = new Properties();
prop.load(in);
String driver = prop.getProperty("driver");
String url = prop.getProperty("url");
String username = prop.getProperty("username");
String password = prop.getProperty("password");
InputStream in = this.getServletContext().getResourceAsStream("/db.properties");
System.out.println(in);
//获取web资源的绝对路径
String path = this.getServletContext().getRealPath("/WEB-INF/classes/db.properties");
FileInputStream in = new FileInputStream(path);
Properties prop = new Properties();
prop.load(in);
String driver = prop.getProperty("driver");
String url = prop.getProperty("url");
String username = prop.getProperty("username");
String password = prop.getProperty("password");
//读取web工程中资源文件
InputStream in = this.getServletContext().getResourceAsStream("/WEB-INF/classes/db.properties");
Properties prop = new Properties();
prop.load(in);
String driver = prop.getProperty("driver");
String url = prop.getProperty("url");
String username = prop.getProperty("username");
String password = prop.getProperty("password");
相关文章推荐
- 【ServletConfig、ServletContext】使用ServletContext、类加载器读取资源文件
- 利用python读取xml布局文件下面使用中文或者引用资源文件里面的中文,并且显示行号
- 使用类装载器读取资源文件
- Android读取资源文件——读取原始Xml内容和使用Menu文件
- 使用Linq读取资源文件
- 2014.09.02 周二-用servletContext、类装载器读取资源文件
- java.util.ResourceBundle使用详解(读取资源属性文件)
- servletContext对象之读取web项目下文件资源
- 在.NET中读取嵌入和使用资源文件的方法
- 使用ResourceBundle国际化资源文件读取properties详解
- java_web11-ServletContext读取Web应用中的资源文件
- 在.NET中读取嵌入和使用资源文件的方法
- ServletContext读取Web应用中的资源文件
- 读取资源属性文件(properties)java.util.ResourceBundle使用详解
- 利用ServletContext对象读取web应用中的资源文件
- 使用Spring中Src下 -context.xml : 用资源文件夹保存数据库的链接信息 并在配置文件里读取
- spring使用ApplicationContext读取资源文件
- ServletContext笔记和servlet和传统方法读取资源文件
- Servlet之ServletContext读取web应用中的资源文件
- java读取资源文件--使用文件流的方式读取