1.通过ClassLoader来加载getResource()时不需要加 "/" 因为source是从main开始的;

Thread.currentThread().getContextClassLoader().getResource("main/test/test.txt").getPath();

2.通过Class.getResource()来加载文件时需要加“/”     classpath 是:/C:/CustomSofter/develop/IDEA/IDEAWorkSpace/C3p0TestPrictice/

String userDir = System.getProperty("user.dir");

print ::::C:\CustomSofter\develop\IDEA\IDEAWorkSpace\C3p0TestPrictice

 

目录结构:

src/main/test

getResource()的使用总结 ;

 

相关文章:

  • 2022-12-23
  • 2021-09-24
  • 2021-04-13
  • 2021-07-27
  • 2022-01-17
  • 2021-07-19
  • 2021-09-19
  • 2021-06-01
猜你喜欢
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2021-09-07
  • 2021-12-10
相关资源
相似解决方案