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");
  • 相关阅读:
    网络协议 19
    网络协议 18
    网络协议 17
    网络协议 16
    网络协议 15
    .NET基础知识(01)-值类型与引用类型
    .NET基础知识(02)-拆箱与装箱
    网络协议 14
    网络协议 13
    网络协议 12
  • 原文地址:https://www.cnblogs.com/chichung/p/10303205.html
Copyright © 2011-2022 走看看