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