java获取src下文件

方式一:

  

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

原文地址:https://www.cnblogs.com/jianguang/p/7070248.html