java读取Properties文件常用两种方式

1.读取项目src目录下文件

[html]  view plain  copy
  1. Properties p = new Properties();  
  2. p.load(this.getClass().getClassLoader().getResourceAsStream("jdbc.properties"));  

2.读取项目WEB-INF目录下文件

[html]  view plain  copy
  1. String pro = this.getClass().getResource("/").getPath().split("WEB-INF")[0]+ "WEB-INF/jdbc.properties";  
  2. FileInputStream fs = new FileInputStream(pro);  
  3. Properties p = new Properties();  
  4. p.load(new InputStreamReader(fs, "utf-8"));  

猜你喜欢

转载自blog.csdn.net/qq_36838191/article/details/80484955