示例图片:

java《六》获取项目路径实例代码_实例代码

实例代码:

package com.util;

import com.xxg.main.Main;

/**
* java获取项目系统路径
* @author yushen
*
*/
public class pathUitl {
//java获取项目系统路径
public static void main(String[] args) {
String u1 = System.getProperty("user.dir");
System.out.println(u1);

String u2 = Thread.currentThread().getContextClassLoader().getResource("").getPath();
System.out.println(u2);

String u3 = Thread.currentThread().getContextClassLoader().getResource(".").getPath();
System.out.println(u3);

String u4 = System.getProperty("java.class.path");
System.out.println(u4);

String u5 = pathUitl.class.getResource("/").toString().substring(6);
System.out.println(u5);

}
}