读取properties资源文件
来源:互联网 发布:国内域名使用 编辑:程序博客网 时间:2024/05/20 11:25
方法一:
在servlet中利用ServletContext对象读取配置文件
this.getServletContext().getResource("/WEB-INF/classes/db.properties");InputStream in = url.openStream();Properties prop = new Properties();prop.load(in);prop.getProperty
this.getServletContext().getRealPath("/WEB-INF/classes/db.properties");FileInputStream in = new FileInputStream(path);Properties prop = new Properties();prop.load(in);prop.getProperty
方法二:
在非servlet程序中如何读取配置文件:用类装载器
//为StudentDao类加载一个类装载器,然后去获得读取资源文件的流(有改动资源文件读取问题).class.getClassLoader().getResourceAsStream("db.properties");.class.getClassLoader().getResourceAsStream("cn/itcast/context/db.properties");
//用类装载方式读取,把资源当作url对待的方式很常见(解决了改动资源文件读取问题).class.getClassLoader().getResource("db.properties"); //获得虚拟路径.getPath(); //获得绝对路径new FileInputStream(path);prop.load(in);
0 0
- 读取properties资源文件
- 读取properties资源文件
- Servlet读取properties资源文件
- 读取资源文件的方法 ApplicationResources.properties
- java.util.Properties 读取资源文件
- java读取ApplicationResources.properties资源文件
- java之资源文件(.properties)读取
- Properties读取properties文件
- Properties 读取 Properties文件
- SystemProperties读取资源文件.properties文件的配置属性
- java读取ApplicationResources.properties资源文件 (转贴)
- 用ResourceBundle类读取properties资源文件的例子。
- Java读取.properties资源文件的常用2种方法
- myeclipse关于properties资源文件的创建和读取
- 使用ResourceBundle国际化资源文件读取properties详解
- Properties文件读取 Message.properties
- 使用Properties类读取资源
- properties资源文件总结
- 关于qsort()的小总结
- 批处理 设定环境变量 大全
- TotalOrderPartitioner的使用
- 表格布局:使用表格布局实现如下界面的设计
- -Puzzles
- 读取properties资源文件
- 明星软件工程师的10种特质
- eclipse c undefined reference to `sqrt'
- 黑马程序员_Java反射技术
- Hibernate get与load区别
- 在ubuntu中E: The package kingsoft-office needs to be reinstalled, but I can't find an archive for it.
- WordPress For SAE 安装/更新方法
- TilesPlugin : Specified RequestProcessor not compatible with TilesRequestProcessor
- 黑马程序员之java编程基础7