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

//第一种方式

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");

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