JAVA WEB 擷取properties檔案,存放路徑 及 擷取路徑

來源:互聯網
上載者:User

標籤:java   javase   javaee   properties   

  首先明白,ClassPath : 指的是:WEB-INF\classes這個目錄下,通常把檔案放在src檔案夾下,或者建立檔案並且添加到build path即可。IDE在同步檔案到tomcat時會自動將檔案放在classes下。

  擷取properties的代碼:

public Properties loadProperties() {Properties properties = new Properties();InputStream stream = this.getClass().getClassLoader().getResourceAsStream("/xxx.properties");try {properties.load(stream);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return properties;}

請注意:路徑
/handlerFactory.properties
有/表示從classpath根目錄下尋找,無/表示從當前包下尋找。

這次被坑的最重要一點:

 Properties檔案名稱首字母不能大寫,

 Properties檔案名稱首字母不能大寫,

 Properties檔案名稱首字母不能大寫,

 大寫了你一輩子找不到檔案。!

重要的事情說三遍!

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

JAVA WEB 擷取properties檔案,存放路徑 及 擷取路徑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.