idea 创建properties配置文件

【转载】原文链接:https://blog.csdn.net/caoPengFlying/article/details/78660379

我们在j2ee当中,连接数据库的时候经常会用到properties配置文件,我们原来在eclipse或者myeclipse当中会在src文件夹目录下创建一个properties文件。然后用如下代码去加载配置文件

 

 InputStream in = PropertiesDemo.class.getClassLoader()
 .getResourceAsStream("database.properties");
 Properties pro = new Properties();
 pro.load(in);

但是我们在idea当中不能这样去新建一个文件,因为在idea有一个文件类型的设置比如这里写图片描述 
src就是sources类型 
而配置文件应该是resources类型。 
所以我们在idea当中新建一个properties时,就要新建一个ResourceBundle类型的文件 
这里写图片描述 
然后为文件起名字就可以了。这样上面的代码就可以读取到properties当中的文件了

posted @ 2018-10-05 19:59  yaochunguang  阅读(899)  评论(0编辑  收藏  举报