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. MySQL命令操作(Linux平台)

    Linux shell 批量创建数据库/表 Shell 脚本如下: # create database and table HOST='localhost' PORT='3306' USER='roo ...

  2. LeetCode 1093. Statistics from a Large Sample

    原题链接在这里:https://leetcode.com/problems/statistics-from-a-large-sample/ 题目: We sampled integers betwee ...

  3. CDN工作机制

    CDN(content delivery network),即内容分布网络,是一种构建在现有Internet上的一种先进的流量分配网络.CDN以缓存网站中的静态数据为主,当用户请求动态内容时,先从CD ...

  4. POJ P3009 Curling 2.0 题解

    深搜,向四个方向,在不越界的情况下一直闷头走,直到撞墙.到达终点就输出,没到就回溯. #include<iostream> #include<cstring> #include ...

  5. 堆内存腐败异常(STATUS_HEAP_CORRUPTION---0xC0000374)

    什么是内存腐败 当堆内存位置的内容由于编程行为而被修改,超出了原始程序构造的意图时,计算机程序就会发生内存腐败,也可以叫内存破坏:这被称为违反内存安全.内存腐败的最可能原因是编程错误.当腐败的内存内容 ...

  6. 计蒜客 39268.Tasks-签到 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest A.) 2019ICPC西安邀请赛现场赛重现赛

    Tasks It's too late now, but you still have too much work to do. There are nn tasks on your list. Th ...

  7. mysql帐号,权限管理

    -> use mysql; //选择数据库 -> select host,user,password from user; //查询已有用户 -> insert into user ...

  8. Clouds Classification from Sentinel-2 Imagery with Deep Residual Learning and Semantic Image Segmentation

    哨兵2号云检测的语义分割,提出了CloudNet,不使用池化和上采样操作,从头到尾保持原图大小,中间每个块使用ASPP和残差连接,网络结构如下 比较了CNN, FCN, DeeplabV3+,效果都没 ...

  9. 大量数据通过Phoenix插入到hbase报错记录(2)

    错误: Caused by: java.sql.SQLException: ERROR (INT10): Unable to find cached index metadata 解决办法: 在hba ...

  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 ...