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");
  • 相关阅读:
    几种芯片封装
    Finder 快捷键
    Linux dnsmasq 服务
    java: private, protected, public
    java final
    Jenkins 搭建
    一款工作记录软件
    MacOS 修改主机名
    Ubuntu 静态IP
    adb tcp 调试
  • 原文地址:https://www.cnblogs.com/chichung/p/10303205.html
Copyright © 2011-2022 走看看