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")



  
 
人生因有期待而美好; 谁不是一边热爱生活,又一边不想活。 学最好的别人,做最好的自己。
原文地址:https://www.cnblogs.com/peoty/p/15139209.html