(CSDN迁移) Java路径获取
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
(CSDN迁移) Java路径获取的更多相关文章
- (CSDN 迁移) JAVA多线程实现-支持定时与周期性任务的线程池(newScheduledThreadPool)
		前几篇文章中分别介绍了 单线程化线程池(newSingleThreadExecutor) 可控最大并发数线程池(newFixedThreadPool) 可回收缓存线程池(newCachedThread ... 
- Java路径获取
		package unit02; /** * * @time 2014年9月18日 下午10:29:48 * @porject ThinkingInJava * @author Kiwi */ publ ... 
- (CSDN 迁移) JAVA多线程实现-可回收缓存线程池(newCachedThreadPool)
		在前两篇博客中介绍了单线程化线程池(newSingleThreadExecutor).可控最大并发数线程池(newFixedThreadPool).下面介绍的是第三种newCachedThreadPo ... 
- (CSDN迁移) JAVA多线程实现-可控最大并发数线程池(newFixedThreadPool)
		上篇文章中介绍了单线程化线程池newSingleThreadExecutor,可控最大并发数线程池(newFixedThreadPool)与其最大的区别是可以通知执行多个线程,可以简单的将newSin ... 
- (CSDN迁移)JAVA多线程实现-单线程化线程池newSingleThreadExecutor
		JAVA通过Executors提供了四种线程池,单线程化线程池(newSingleThreadExecutor).可控最大并发数线程池(newFixedThreadPool).可回收缓存线程池(new ... 
- (CSDN 迁移) JAVA循环删除List的某个元素
		若列表中只可能存在一个则可以用简单的循环删除,不多说. 若列表中可能存在多个,尤其是可能有多个连续的需要删除,用简单循环有可能发生异常. 需要使用迭代器(Iterator),两种具体实现: 逻辑上是一 ... 
- (CSDN迁移) JAVA多线程实现-实现Runnable接口
		实现Runnable接口 implements Runnable 重写run()方法 @Override public void run(){//TODO} 创建线程对象: Thread threa ... 
- (CSDN迁移)JAVA多线程实现-继承Thread
		继承Thread方法: extends Thread 重写覆盖run()方法: @Override public void run() 通过start()方法启动线程. threadDemo01.st ... 
- Java文件获取路径方式:
		转自:http://blog.csdn.net/appleprince88/article/details/11599805# 谢谢! 由于经常需要获取文件的路径,但是比较容易忘记,每次需要总需要查询 ... 
随机推荐
- Backpressure & Elastic Scaling
			spark.streaming从不稳定到稳定状态,解决数据量接收数据时突然变大,使得无法及时处理数据,稳定性得到保证 开启方式: spark.streaming.backpressure.enable ... 
- websocket简单样例
			服务端 var server = require('ws').Server; }); serv.on('connection',function(socket){ socket.send('hello ... 
- apache commons-configuration包读取配置文件
			1.pom依赖添加 <!-- 配置文件读取 --> <dependency> <groupId>commons-configuration</groupId& ... 
- OLED液晶屏幕(2)取模软件
			https://blog.csdn.net/ling3ye/article/details/53399305 文件夹说明: Adafruit_SSD1306-master ——SSD1306库(O ... 
- CSS行内元素
			一.典型代表 span a ,strong em del, ins 二.特点: 在一行上显示 不能直接设置宽高 元素的宽和高就是内容撑开的宽高. <style type="text/c ... 
- python 报can't subtract offset-naive and offset-aware datetimes错误
			两个时间一个含时区,一个不含时区 
- Linux 系统管理——账号管理
			一.用户账号管理 1.用户账户概述 用户账户的常见分类: 超级用户:root uid=0 gid=0 权限最大 普通用户:uid>=500 做一般权限的系统管理,权限有限. 程序用户:1 ... 
- uni app 零基础小白到项目实战-1
			uni-app是一个使用vue.js开发跨平台应用的前端框架. 开发者通过编写vue.js代码,uni-app将其编译到Ios,android,微信小程序等多个平台,保证其正确并达到优秀体验. Uni ... 
- xmind 破解
			邮箱:x@iroader 序列号: XAka34A2rVRYJ4XBIU35UZMUEEF64CMMIYZCK2FZZUQNODEKUHGJLFMSLIQMQUCUBXRENLK6NZL37JXP4P ... 
- 【POJ3083】Children of the Candy Corn
			本题传送门 本题知识点:深度优先搜索 + 宽度优先搜索 本题题意是求三个路径长度,第一个是一直往左手边走的距离,第二个是一直往右手边走的距离,第三个是最短距离. 第三个很好办,就是一个简单的bfs的模 ... 
