码迷,mamicode.com
首页 > 数据库 > 详细

JDBCUtils工具类配置文件的读取方式

时间:2017-06-08 01:20:04      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:cut   bsp   source   get   配置   use   对象   inpu   文件的   

//第一种方式

Properties prop= new Properties();
        //读取文件   通过类加载读取
        InputStream is = JDBCUtils.class.getClassLoader().getResourceAsStream("data.properties");
        prop.load(is);
        String driverClass = prop.getProperty("driverClass");
        String url = prop.getProperty("url");

        String username = prop.getProperty("username");

        String password = prop.getProperty("password");

//第二种方式

        Properties properties = new Properties();

        // 读取属性文件:使用Java中Properties的对象.

        InputStream is = new FileInputStream("src/jdbc.properties");

        properties = new Properties();

        properties.load(is);

        String driverClass = properties.getProperty("driverClass");

        String url = properties.getProperty("url");

        String username = properties.getProperty("username");
        String password = properties.getProperty("password");

JDBCUtils工具类配置文件的读取方式

标签:cut   bsp   source   get   配置   use   对象   inpu   文件的   

原文地址:http://www.cnblogs.com/lijingbo/p/6959650.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!