Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Java读取src下的配置文件

新建一个普通的Java项目,在src目录下有一config.propertes文件。配置文件里面的内容如下(就一句话):  driverURL = jdbc:mysql://127.0.0.1:3306/evan下面是读取配置文件的java代码:package com.evan;import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;public class ReadProperties { public static void main(String[] args) throws IOException {
  InputStream is = ReadProperties.class.getResourceAsStream("/config.properties");
 
  Properties properties = new Properties();
 
  properties.load(is);
 
  is.close();
  String driverURL = properties.getProperty("driverURL");
 
  /*
 * 輸入結果为:jdbc:mysql://127.0.0.1:3306/evan
 */
  System.out.println(driverURL);
 }
}项目的目录如下: