码迷,mamicode.com
首页 > 编程语言 > 详细

Java路径获取

时间:2017-05-29 14:07:27      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:data   return   lips   获取   bin   int()   point   thinking   think   


package unit02;

/**
 * 
 * @time 2014年9月18日 下午10:29:48
 * @porject ThinkingInJava
 * @author Kiwi
 */
public class Test03 {
	
	private String getPathByPoint() {
		return this.getClass().getClassLoader().getResource(".").getPath();
	}
	
	private String getPathByNothing() {
		return this.getClass().getClassLoader().getResource("").getPath();
	}
	
	private String getResourcePath() {
		return this.getClass().getResource("").getPath();
	}
	
	private String getResourcePathByPoint() {
		return this.getClass().getResource(".").getPath();
	}
	
	private String getThreadPath() {
		return Thread.currentThread().getContextClassLoader().getResource("").getPath();
	}
	
	private String getThreadPathByPoint() {
		return Thread.currentThread().getContextClassLoader().getResource(".").getPath();
	}

	public static void main(String[] args) {
		Test03 test03 = new Test03();
		System.out.println("this.getClass().getClassLoader().getResource(\".\").getPath() = \n" + test03.getPathByPoint());
		System.out.println("this.getClass().getClassLoader().getResource(\"\").getPath() = \n" + test03.getPathByNothing());
		
		System.out.println("this.getClass().getResource(\"\").getPath() = \n" + test03.getResourcePath());
		System.out.println("this.getClass().getResource(\".\").getPath() = \n" + test03.getResourcePathByPoint());
		
		System.out.println("Thread.currentThread().getContextClassLoader().getResource(\"\").getPath() = \n" + test03.getThreadPath());
		System.out.println("Thread.currentThread().getContextClassLoader().getResource(\".\").getPath() = \n" + test03.getThreadPathByPoint());

		System.out.println(System.getProperty("user.dir"));
		System.out.println(System.getProperty("java.class.path"));
	}

}
执行结果:(注:測试环境:Eclipse。 项目名称:ThinkingInJava;包名称:unit02)
this.getClass().getClassLoader().getResource(".").getPath() = 
/F:/java/java_workspace/ThinkingInJava/bin/
this.getClass().getClassLoader().getResource("").getPath() = 
/F:/java/java_workspace/ThinkingInJava/bin/
this.getClass().getResource("").getPath() = 
/F:/java/java_workspace/ThinkingInJava/bin/unit02/
this.getClass().getResource(".").getPath() = 
/F:/java/java_workspace/ThinkingInJava/bin/unit02/
Thread.currentThread().getContextClassLoader().getResource("").getPath() = 
/F:/java/java_workspace/ThinkingInJava/bin/
Thread.currentThread().getContextClassLoader().getResource(".").getPath() = 
/F:/java/java_workspace/ThinkingInJava/bin/
F:\java\java_workspace\ThinkingInJava
F:\java\java_workspace\ThinkingInJava\bin;F:\java\java_workspace\code\mindview.jar



   

Java路径获取

标签:data   return   lips   获取   bin   int()   point   thinking   think   

原文地址:http://www.cnblogs.com/yfceshi/p/6917847.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!