JDBC使用反射读取properties文件方法笔记
来源:互联网 发布:北京尚学堂java学费 编辑:程序博客网 时间:2024/06/03 13:13
1,配置文件放到src下
2,代码片段
public class CMConstant {public static String getConfigureParameterFromJDBC(String paramString) {String str = CMConstant.getRootPath() + File.separator + "WEB-INF"+ File.separator + "classes/config.properties";Properties localProperties = new Properties();try {FileInputStream localFileInputStream = new FileInputStream(str);localProperties.load(localFileInputStream);localFileInputStream.close();} catch (FileNotFoundException localFileNotFoundException) {logger.error("读取属性文件--->失败!- 原因:文件路径错误或者文件不存在");localFileNotFoundException.printStackTrace();return null;} catch (IOException localIOException) {logger.error("装载文件--->失败!");localIOException.printStackTrace();}return localProperties.getProperty(paramString);}public static String getRootPath() {String result = null;try {result = CMConstant.class.getResource("CMConstant.class").toURI().getPath().toString();} catch (URISyntaxException e1) {e1.printStackTrace();}int index = result.indexOf("WEB-INF");if (index == -1) {index = result.indexOf("bin");}result = result.substring(1, index);if (result.endsWith("/"))result = result.substring(0, result.length() - 1);// 不包含最后的"/"return result;}<span style="white-space:pre"></span>/** * 查找config/jdbc.properties里值 * @Description: @param key * @Description: @return * @Last Modified: , Date Modified: */public static String getJDBCValue(String key) {String filePath = getRootPath() + File.separator + "WEB-INF\\classes"+ File.separator + "config.properties";Properties propertie = new Properties();try {FileInputStream inputFile = new FileInputStream(filePath);propertie.load(inputFile);inputFile.close();} catch (FileNotFoundException ex) {ex.printStackTrace();return null;} catch (IOException ex) {ex.printStackTrace();}return propertie.getProperty(key);}}
0 0
- JDBC使用反射读取properties文件方法笔记
- Java学习笔记——JDBC读取properties属性文件
- Java学习笔记——JDBC读取properties属性文件
- 利用反射读取Properties文件
- 使用J2SEAPI读取Properties文件的方法
- 读取jdbc.properties文件,信息入库
- 【SQL】JDBC读取properties属性文件
- 读取配置jdbc.properties文件连接数据库
- 在配置文件中读取:jdbc.properties文件
- java项目中读取jdbc.properties文件
- 【SQL】JDBC读取properties属性文件
- 读取properties文件的方法
- 读取Properties文件的方法
- java读取properties文件方法
- java 读取properties文件方法
- Spring 使用配置文件读取jdbc.properties
- Spring使用配置文件读取jdbc.properties
- Spring使用配置文件读取jdbc.properties
- List接口源码解析
- 这些输入格式是ChemDraw 15可以支持吗
- java中添加按钮并添加响应事件
- Errors running builder 'DeploymentBuilder' on project 'webdemo'.java.lang.NullPointerException
- Nginx开发从入门到精通
- JDBC使用反射读取properties文件方法笔记
- 正则表达式及API
- Discuz!X数据库函数操作命令(转载)
- shell 嵌套 变量 【 型如 $(( $num1 + $num2)) 】 -1
- 设计模式(四):单例模式Singleton(创建型模式)
- OO与设计模式第二次复习
- 对Rxjava1.0的map方法的源码分析
- blob类型的数据,可以保存图片,直接把图片转化为代码,和text不同,editkindor常用到
- DZY Loves Balls