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路径获取的更多相关文章

  1. (CSDN 迁移) JAVA多线程实现-支持定时与周期性任务的线程池(newScheduledThreadPool)

    前几篇文章中分别介绍了 单线程化线程池(newSingleThreadExecutor) 可控最大并发数线程池(newFixedThreadPool) 可回收缓存线程池(newCachedThread ...

  2. Java路径获取

    package unit02; /** * * @time 2014年9月18日 下午10:29:48 * @porject ThinkingInJava * @author Kiwi */ publ ...

  3. (CSDN 迁移) JAVA多线程实现-可回收缓存线程池(newCachedThreadPool)

    在前两篇博客中介绍了单线程化线程池(newSingleThreadExecutor).可控最大并发数线程池(newFixedThreadPool).下面介绍的是第三种newCachedThreadPo ...

  4. (CSDN迁移) JAVA多线程实现-可控最大并发数线程池(newFixedThreadPool)

    上篇文章中介绍了单线程化线程池newSingleThreadExecutor,可控最大并发数线程池(newFixedThreadPool)与其最大的区别是可以通知执行多个线程,可以简单的将newSin ...

  5. (CSDN迁移)JAVA多线程实现-单线程化线程池newSingleThreadExecutor

    JAVA通过Executors提供了四种线程池,单线程化线程池(newSingleThreadExecutor).可控最大并发数线程池(newFixedThreadPool).可回收缓存线程池(new ...

  6. (CSDN 迁移) JAVA循环删除List的某个元素

    若列表中只可能存在一个则可以用简单的循环删除,不多说. 若列表中可能存在多个,尤其是可能有多个连续的需要删除,用简单循环有可能发生异常. 需要使用迭代器(Iterator),两种具体实现: 逻辑上是一 ...

  7. (CSDN迁移) JAVA多线程实现-实现Runnable接口

    实现Runnable接口  implements Runnable 重写run()方法 @Override public void run(){//TODO} 创建线程对象: Thread threa ...

  8. (CSDN迁移)JAVA多线程实现-继承Thread

    继承Thread方法: extends Thread 重写覆盖run()方法: @Override public void run() 通过start()方法启动线程. threadDemo01.st ...

  9. Java文件获取路径方式:

    转自:http://blog.csdn.net/appleprince88/article/details/11599805# 谢谢! 由于经常需要获取文件的路径,但是比较容易忘记,每次需要总需要查询 ...

随机推荐

  1. intellij idea参数提示param hints

    https://jingyan.baidu.com/article/5225f26bae80f4e6fa0908b1.html

  2. 合并K个有序链表

    方法一:采用归并的思想将链表两两合并,再将两两合并后的链表做同样的操作直到合并为只有一个新的链表为止. 归类的时间复杂度是O(logn),合并两个链表的时间复杂度是O(n),则总的时间复杂度大概是O( ...

  3. Build Post Office

    Description Given a 2D grid, each cell is either an house 1 or empty 0 (the number zero, one), find ...

  4. Fast + Small Docker Image Builds for Rust Apps

    转自:https://shaneutt.com/blog/rust-fast-small-docker-image-builds/ In this post I’m going to demonstr ...

  5. rac集群状态脚本执行awk拼接有问题

    再shell中拿出来拼接没问题,在脚本中运行就有问题,

  6. js中forEach,for in,for of循环的用法详解

    一.一般的遍历数组的方法: var array = [1,2,3,4,5,6,7]; for (var i = 0; i < array.length; i) { console.log(i,a ...

  7. 【POJ2251】Dungeon Master

    本题传送门 本题知识点:宽度优先搜索 题意简单.在一个L层高的楼里,去走迷宫,就是问从S走到E的最短路径.每走一格每上或者下一层都算1步. 一开始以为这个"立体迷宫"有点吓到我(题 ...

  8. PHP 之根据两个经纬度计算距离

    一.函数代码 /** * @param $lng1 * @param $lat1 * @param $lng2 * @param $lat2 * @return float */ function g ...

  9. Luogu3379 【模板】最近公共祖先(LCA)

    题面 题解 这里讲一种硬核做法. 首先\(\mathrm{dfs}\)整棵树,求出这棵树的欧拉序,然后\(\mathrm{LCA}\)问题就变成了\(\pm 1\mathrm{RMQ}\)问题. 考虑 ...

  10. Linux 踢掉其他终端用户

    输入W查看信息 root@HAN:~# w 09:02:36 up 8 days, 20:10, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FRO ...