網(wǎng)站首頁 編程語言 正文
關(guān)于class.getClassLoader().getResourceAsStream()和class.getResourceAsStream()的用法
作者:Jothan Zhong 更新時間: 2024-01-06 編程語言1.class.getResourceAsStream()
①.不加‘ / ’,直接在包的路徑下開始尋找,相當(dāng)于在已經(jīng)寫好的path前面加了一句 /包名/path
②加‘ / ’,就要從classpath的那一層開始找
比如,找到存放編譯后的class存放的位置:
//文件目錄
yx
jdbctest
com
A.class
B.class
1.properties```
2.properties
//調(diào)用1.properties
InputStream inputStream=PropertiesTest.class.getResourceAsStream("1.properties");
InputStream inputStream=PropertiesTest.class.getResourceAsStream("/yx/jdbctest/com/1.properties");
//調(diào)用2.properties
InputStream inputStream=PropertiesTest.class.getResourceAsStream("/2.properties");
123456789101112131415
2.class.getClassLoader().getResourceAsStream()
getClassLoader是直接從classpath開始查找文件的,因此使用這個就需要定位在classpath這個位置,也就是下面目錄中yx這一層。
//文件目錄
yx
jdbctest
com
A.class
B.class
1.properties```
2.properties
//調(diào)用1.properties
InputStream inputStream=PropertiesTest.class.getClassLoader().getResourceAsStream("yx/jdbctest/com/1.properties");
//調(diào)用2.properties
InputStream inputStream=PropertiesTest.class.getClassLoader().getResourceAsStream("2.properties");
12345678910111213
另外,如果你在整個工程目錄下建立一個resource文件,編譯之后,它會存到和yx同級的這個目錄下,也就是classpath這里,如果建立的是一個test resource 那就會在這一層的上面一層中,這個等以后寫了完整的程序出來,在做進(jìn)一步的整理。
原文鏈接:https://blog.csdn.net/qq_43985303/article/details/135377550
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-12-08 Apache?Cordova?Android原理應(yīng)用實例詳解_Android
- 2022-04-23 Python繪制燈籠的示例代碼_python
- 2022-07-08 Python實現(xiàn)超快窗口截圖功能詳解_python
- 2023-03-20 一文詳解pygame.sprite的精靈碰撞_python
- 2022-04-20 C語言特殊符號的補充理解_C 語言
- 2022-08-10 python中ThreadPoolExecutor線程池和ProcessPoolExecutor進(jìn)程
- 2022-10-28 MPAndroidChart繪制自定義運動數(shù)據(jù)圖表示例詳解_Android
- 2022-12-13 Dart多態(tài)控制反轉(zhuǎn)編碼規(guī)范實例詳解_Dart
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支