1. console模式下:

     String fileDir = Thread.currentThread().getContextClassLoader().getResource("./").getPath();

     或者               =  PropertiesFacoty.class.getClassLoader().getResource("./").getPath();

     或 URL fileDir = PropertiesFacoty.class.getResource(".");

     在web容器中直接获取到系统的lib目录而不是项目的。

 

2. web容器模式下:

     ServletContext context;

     String path = context.getRealPath("") + "\\WEB-INF\\classes\\";  通过ServletContext获取

 

相关文章:

  • 2021-12-09
  • 2022-02-07
  • 2021-12-01
  • 2021-07-03
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-01
  • 2021-12-09
  • 2022-02-20
  • 2022-12-23
  • 2021-12-09
相关资源
相似解决方案