首页 > 其他 > 详细

读取properties文件

时间:2018-10-12 23:06:45      阅读:186      评论:0      收藏:0      [点我收藏+]

  读取 配置文件的两个方法

1.  xxx.class.getClassLoader() .getResourceAsStream(xxxx) 

 

1 Properties p  =new Properties();
2         p.load(Test.class.getClassLoader()
3                 .getResourceAsStream
4                 ("com/springFactory/spring.properties"));;
5         // properties文件放在了  src 目录  
6         // 编译后,properties 文件会在 bin目录(即classpath)
7         
8         String  vehicleTypeName  = p.getProperty("VehicleType");
9         System.out.println(vehicleTypeName);

技术分享图片

 

 

2.

InputStream in = Thread.currentThread().

getContextClassLoader().
getResourceAsStream("jdbc.properties");
p.load(in);

 技术分享图片

 

读取properties文件

原文:https://www.cnblogs.com/kwaitfort/p/9780830.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!