一 获取类路径
1
java.io.File f = new java.io.File(this.getClass().getResource("/").getPath());
System.out.println(" path1 = " + f.getAbsolutePath());
2
URL xmlpath = this.getClass().getClassLoader().getResource("");
System.out.println(" path2 = " + xmlpath);
二 获取项目路径
1
java.io.File directory = new java.io.File("");// 参数为空
String courseFile = directory.getCanonicalPath();
System.out.println("path1= " + courseFile);
2
System.out.println(" path1= = " + System.getProperty("user.dir"));