(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# 谢谢! 由于经常需要获取文件的路径,但是比较容易忘记,每次需要总需要查询 ...
随机推荐
- Laravel —— 特殊分页
项目中,分页经常会用到. Laravel 中也自带了分页功能. 但有些时候需要稍作修改,来满足自己的需求. 一.普通分页 1.控制器中,用 paginate() 方法. $users = DB::ta ...
- 纯js房贷计算器开源
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- static final与final修饰的常量有什么不同
最近重头开始看基础的书,对一些基础的概念又有了一些新的理解,特此记录一下 static final修饰的常量: 静态常量(static修饰的全部为静态的),编译器常量,编译时就确定其值(java代码经 ...
- lower_bound( )和upper_bound( )怎么用嘞↓↓↓
lower_bound( )和upper_bound( )都是利用二分查找的方法在一个排好序的数组中进行查找的. 在从小到大的排序数组中, lower_bound( begin,end,num):从数 ...
- vue Uncaught SyntaxError: Unexpected token < 报错
这个问题是因为项目中出现没有闭合的标签,如<img src=""> 需改成<img src="xxx.png"/>
- Tcl数学运算
expr 数学表达式 Tcl支持的数学操作符(优先级按照从高到低): -一元负号 +一元正号 ~按位取反 !逻辑非 *乘 /除 %取余 +加号 -减号 <<左移位 >>右移位 ...
- GIT 使用记录,新手->会用(mac 用户)
(唔,mac 用户这个要求是因为集成在 terminal 中可直接使用) 1. github 中 创建 git 账户 2. github -> 在个人设置中 找到 ssh and GPGkey ...
- Java 12 骚操作, String居然还能这样玩!
Java 13 都快要来了,12必须跟栈长学起! Java 13 即将发布,新特性必须抢先看! 栈长之前在Java技术栈微信公众号分享过<Java 11 已发布,String 还能这样玩!> ...
- 微信小程序之页面传参
效果图: 点击编辑值传过去了,那么编辑支出类型这个界面又是如何获取到值呢? 传值代码: type.js editType: function (e) { var typeId = e.currentT ...
- js写入和读取cookie
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content ...