Java加载Prperties资源

1.
Properties pro = new Properties();
InputStream is = DruidDemo.class.getClassLoader().getResourceAsStream("druid.properties");
 pro.load(is);
 DataSource ds=DruidDataSourceFactory.createDataSource(pro);
 

2.
  URL url = DruidDemo.class.getClassLoader().getResource("druid.properties");
String path = url.getPath();
pro.load(new FileReader(path));
  url=pro.getProperty("url");

3. 获取application.properties文件
  ResourceBundle bundle= ResourceBundle.getBundle("application", Locale.CHINA);
  String address=bundle.getString("url")



  
 
posted @ 2021-08-13 21:35  一叶小舟1  阅读(56)  评论(0编辑  收藏  举报