zoukankan      html  css  js  c++  java
  • 配置文件的读取

    (1)配置文件放在项目的根目录下

    Properties properties = new Properties();
    InputStream is = new FileInputStream("config.properties");
    
    // 导入输入流
    properties.load(is);
    
    // 读取
    driverClass = properties.getProperty("driverClass");
    url = properties.getProperty("url");
    username = properties.getProperty("username");
    password = properties.getProperty("password");

    (2)配置文件放在src目录下

    Properties properties = new Properties();
    InputStream is = JDBCutils.class.getClassLoader().getResourceAsStream("config.properties");
    
    // 导入输入流
    properties.load(is);
    
    // 读取
    driverClass = properties.getProperty("driverClass");
    url = properties.getProperty("url");
    username = properties.getProperty("username");
    password = properties.getProperty("password");
  • 相关阅读:
    计算几何
    差三角
    约瑟夫
    字符编码
    河南省赛之Substring
    移动字母
    抽屉原理
    不要为了完成代码而写代码
    分布式文件系统优化
    降低代码的复杂度
  • 原文地址:https://www.cnblogs.com/chichung/p/10303205.html
Copyright © 2011-2022 走看看