java获取src下文件

时间:2022-11-26 14:45:16

方式一:

  

InputStream in = Test.class   
.getResourceAsStream(
"/env.properties");
URL url
= Test.class.getResource("env.properties") ;

 说明:env.properties文件在src的根目录下,文件名前有斜杠

方式二:

InputStream in = Test.class.getClassLoader()    
.getResourceAsStream(
"env.properties");
URL url
= Test.class.getClassLoader().getResource("env.properties") ;

方式三:

InputStream in = Thread.currentThread().getContextClassLoader()  
.getResourceAsStream(
"ExcelModeMappingl.xml");

原贴地址:https://yq.aliyun.com/articles/40852