classpath文件加载进内存
java方式
this.getClass().getClassLoader().getResourceAsStream()
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("application.properties"); //转Properties对象
Properties properties = new Properties(); properties.load(resourceAsStream);
spring方式
ClassPathResource
ClassPathResource classPathResource = new ClassPathResource("application.properties"); InputStream inputStream = classPathResource.getInputStream();