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-2025 CODEPRJ.COM