参考原文:
-
优快云| Java获取类路径的方式:
https://blog.youkuaiyun.com/An1090239782/article/details/82590011 -
Java如何获取当前的jar包路径以及如何读取jar包中的资源:https://www.cnblogs.com/zeciiii/p/4178824.html
获取项目路径、类加载路径、当前类路径,和在jar包中运行的结果对比
public void printPath() throws IOException {
/*
* 获取项目路径
*/
System.out.println("**获取项目路径**");
System.out.print("\t1.利用File类提供的方法 获取项目路径-----\n\t");
//1. (利用File类提供的方法 获取项目路径)
File directory = new File("");// 参数为空
String courseFile = directory.getCanonicalPath();
System.out.println(courseFile);
System.out.print("\t2.System.getProperty()函数获取项目路径-----\n\t");
//2. (System.getProperty()函数获取项目路径)
String property = System.getProperty("user.dir"