java讀取classpath下properties文件注意事項


1.properties文件在classpath根路徑下讀取方式

Properties properties = new Properties();
properties.load(BlogIndex.class.getResourceAsStream("/config.properties"));

2.properties文件在package路徑下讀取方式

Properties properties = new Properties();
properties.load(BlogIndex.class.getResourceAsStream("com/test/config.properties"));

特別提醒:

第一種方式的文件名稱前必須加 /


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM