读取properties文件
读取 配置文件的两个方法
1. xxx.class.getClassLoader() .getResourceAsStream(xxxx)
Properties p =new Properties(); p.load(Test.class.getClassLoader() .getResourceAsStream ("com/springFactory/spring.properties"));; // properties文件放在了 src 目录 // 编译后,properties 文件会在 bin目录(即classpath) String vehicleTypeName = p.getProperty("VehicleType"); System.out.println(vehicleTypeName);


2.
InputStream in = Thread.currentThread().
getContextClassLoader().
getResourceAsStream("jdbc.properties");
p.load(in);

3. 放在 resources 目录

posted on 2018-10-12 21:31 wait_for_you 阅读(170) 评论(0) 收藏 举报
浙公网安备 33010602011771号