public static void main(String[] args){
System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
System.out.println(HibernateMappingManager.class.getClassLoader().getResource(""));
System.out.println(ClassLoader.getSystemResource(""));
System.out.println(HibernateMappingManager.class.getResource(""));
System.out.println(HibernateMappingManager.class.getResource("/")); //Class文件所在路径
System.out.println(new File("/").getAbsolutePath());
System.out.println(System.getProperty("user.dir"));
String rootSrc = System.getProperty("user.dir");
String xmlSrc = rootSrc + "\\hrJava\\config\\hbmxml";
System.out.println(xmlSrc);
}
获得当前所在项根路径的方法
最新推荐文章于 2023-04-12 19:15:00 发布
本文通过Java代码演示了如何使用不同方式获取类路径下的资源文件位置,包括利用当前线程上下文类加载器、特定类的类加载器、系统类加载器以及直接通过类对象来获取资源。
5644

被折叠的 条评论
为什么被折叠?



