java《六》获取项目路径实例代码
原创
©著作权归作者所有:来自51CTO博客作者宇神城主_蒋浩宇的原创作品,请联系作者获取转载授权,否则将追究法律责任
示例图片:
实例代码:
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);
}
}