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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM