class.getClassLoader().getResourceAsStream(name)擷取設定檔

來源:互聯網
上載者:User

標籤:class   blog   java   http   com   get   

  最近做類比登陸,需要載入一些設定檔,用到了class.getClassLoader().getResourceAsStream(name)方法來擷取js檔案資料流,讀取相對路徑檔案一直是我苦惱的事情……在不斷的百度百度中,終於有了一些結果。

  ClassLoader.getResourceAsStream()尋找資源,是當前類編譯為class檔案後所在檔案夾路徑中尋找,舉例說明:

  在PasswordUtil.java中調用md5.js檔案獲得密碼加密結果(無用,可忽略)

  

  編譯class檔案後儲存路徑在當前project的.classpath中得到:

  

  可以看到,資源檔儲存路徑與class檔案儲存體路徑相同,因此,name直接命名為md5.js就可以了。

菜鳥一枚,只是在這裡mark一下~~~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.