读取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 目录

原文地址:https://www.cnblogs.com/kwaitfort/p/9780830.html