一、项目子目录下创建一个文件夹(命名为config)
二 、放入properties文件到(config)目录
三、把config目录变成资源文件
具体代码如下:
public static void readFile() { try { InputStream is = JdbcUtil.class.getClassLoader().getResourceAsStream("JDBC.properties"); // 创建properties对象 Properties pr = new Properties(); pr.load(is); // 读取配置文件内的内容 driver = pr.getProperty("driver"); url = pr.getProperty("url"); user = pr.getProperty("user"); password = pr.getProperty("password"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
本文地址:https://blog.csdn.net/tao9066/article/details/108856433
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论