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);
		 
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_42749765/article/details/81561048