读取properties文件

  读取 配置文件的两个方法

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

 

猜你喜欢

转载自www.cnblogs.com/kwaitfort/p/9780830.html