读取src下的配置文件

来源:互联网 发布:ubuntu mldonkey 安装 编辑:程序博客网 时间:2024/06/10 22:17

db.properties为src下的数据库配置文件,路径为config/props/db.properties

//读取数据库配置文件public List<String> readDbProps(){List<String> propList = new ArrayList<String>();ClassLoader classLoader = DBConnection.class.getClassLoader();Properties props = new Properties();InputStream is =classLoader.getResourceAsStream("config" + File.separator + "props" + File.separator + "db.properties");try {props.load(is);propList.add(props.getProperty("user"));propList.add(props.getProperty("password"));propList.add(props.getProperty("database"));propList.add(props.getProperty("dbBackupSystem"));}catch (Exception e) {propList = null;logger.error(e.getMessage(),e);}return propList;}


db.properties配置文件内容为
url=jdbc:mysql://127.0.0.1:3306/dimdbuser=rootpassword=123database=dimdb


0 0
原创粉丝点击