简单读取dataSource.properties配置文件
来源:互联网 发布:淘宝信誉提升 编辑:程序博客网 时间:2024/05/01 10:53
package common.newEntity;import java.io.FileInputStream;import java.io.IOException;import java.util.Properties;import org.springframework.core.io.ClassPathResource;/** * ******************************************************** * @ClassName: newEntity * @Description: * @author DoDo * @date 2017-12-27 下午06:29:37 ******************************************************* */public class newEntity { //读取配置文件 public static void main(String[] args) throws Exception { //读取方式一 // ClassPathResource的作用,如果没有指定相对的类名,该类将从类的根路径开始寻找某个 resource,如果指定了相对的类名,则根据指定类的相对路径来查找某个resource // ClassPathResource cr = new ClassPathResource("com.md.util/dataSource.properties");//会重新加载spring框架 ClassPathResource cr = new ClassPathResource("dataSource.properties"); // properties是配置文件,主要的作用是通过修改配置文件可以方便的修改代码中的参数,实现不用改class文件即可灵活变更参数。(方便使用) Properties pros = new Properties(); try { //Properties的load方法其实就是传进去一个输入流,字节流或者字符流,字节流利用InputStreamReader转化为字符流, //然后字符流用BufferedReader包装,BufferedReader读取properties配置文件 pros.load(cr.getInputStream()); System.out.println(pros.getProperty("driver")); } catch (IOException ex) { System.out.println("数据库连接文件不存在"); } //读取方式二 Properties properties=new Properties(); properties.load(new FileInputStream("E:/dataSource.properties")); System.out.println(properties.getProperty("driver")); } }
输出:
com.mysql.jdbc.Driver
com.mysql.jdbc.Driver
2 0
- 简单读取dataSource.properties配置文件
- spring 配置文件datasource.properties
- 读取properties配置文件(简单版)
- java 中简单读取Properties配置文件
- 读取配置文件properties的简单方式
- 简单的properties配置文件读取类
- 在ssh中 无法读取数据源配置文件 dataSource.properties 的问题
- java 读取properties配置文件
- Java读取properties配置文件
- 读取properties配置文件
- java读取properties配置文件
- java 读取配置文件properties
- 读取.properties配置文件
- java 读取*.properties配置文件
- Java读取properties配置文件
- java 读取配置文件(properties)
- java读取 .properties配置文件
- Properties 读取配置文件
- UVa 12665
- elk(1)-趁离职总结下我前公司elk方案
- leetcode解题之 Combination Sum java 版(组合求和)
- Docker下centos6 + mha全记录
- SpringMVC和Mybatis的整合
- 简单读取dataSource.properties配置文件
- 动态规划粗浅理解及LCS思路
- From Word Embeddings To Document Distances
- 一维数组的移动
- git 客户端解决冲突文件
- Failed to read candidate component class: file [F:\eclipse neon\.metadata\.plugins\org.eclipse.wst.s
- Find All Numbers Disappeared in an Array
- 六、简单查询、条件查询、排序
- 对fork()函数的初步认识