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

  1. (CSDN迁移) Java路径获取

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

  2. JAVA中获取路径

    内容来自于snannan_268 关键字: java中获取路径 JAVA中获取路径: 1.jsp中取得路径:   以工程名为TEST为例: (1)得到包含工程名的当前页面全路径:request.get ...

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

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

  4. java中获取路径中的空格处理(%20)问题

    在java中获取文件路径的时候,有时候会获取到空格,但是在中文编码环境下,空格会变成“%20”从而使得路径错误. 解决办法: String path = Parameter.class.getReso ...

  5. Java学习-009-文件名称及路径获取实例及源代码

    此文源码主要为应用 Java 获取文件名称及文件目录的源码及其测试源码.若有不足之处,敬请大神指正,不胜感激!源代码测试通过日期为:2015-2-3 00:02:27,请知悉. Java获取文件名称的 ...

  6. Java中获取路径的方法_自我分析

    就目前的我来说最常用的两种获取路径的方法是  class.getRecource(filename) 和 class.getclassloader.getRecource(filename) 这两者的 ...

  7. Java中获取文件路径

    Java中获取文件路径 1.实例说明 (1)得到 ClassPath的绝对URI路径 Thread.currentThread().getContextClassLoader().getResourc ...

  8. Java中获取项目根路径和类加载路径的7种方法

    引言 在web项目开发过程中,可能会经常遇到要获取项目根路径的情况,那接下来我就总结一下,java中获取项目根路径的7种方法,主要是通过thisClass和System,线程和request等方法. ...

  9. java最全的获取某个接口或者某个类所有对应的所有实现类和继承类的工具类--反射动态获取、非动态获取、按照路径获取等总结

    我们直接上代码吧,代码中有注释说明. //直接看代码吧 import java.io.File; import java.lang.reflect.Field; import java.net.URL ...

随机推荐

  1. 浅谈自学Python之路(day2)

    今天的主要内容是: 标准库 数据类型知识 数据运算 三元运算 bytes类型 字符串操作 字典 集合 标准库 Python的强大之处在于他有非常丰富和强大的标准库和第三方库,几乎你想实现的任何功能都有 ...

  2. UILabel垂直方向显示(上下的顺序显示)。

    NSString* text = @"一"; NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFont ...

  3. C - Haiku

    Problem description Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syl ...

  4. Laravel5.1学习笔记9 系统架构1 请求生命周期 (待修)

    Request Lifecycle Introduction Lifecycle Overview Focus On Service Providers Introduction When using ...

  5. 快速搭建tab

    1. 布局文件代码: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.a ...

  6. 【Oracle】DG三种保护模式及切换方式

    一.三种保护方式 Required Redo Transport Attributes for Data Protection Modes Maximum Availability Maximum P ...

  7. js动态操作订单表格

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. (转)C#开发微信门户及应用(4)--关注用户列表及详细信息管理

    http://www.cnblogs.com/wuhuacong/p/3695213.html 在上个月的对C#开发微信门户及应用做了介绍,写过了几篇的随笔进行分享,由于时间关系,间隔了一段时间没有继 ...

  9. BRAFT EDITOR富文本编辑器

    https://braft.margox.cn/demos/basic     官方文档 import React from 'react' import Uploading from '../Upl ...

  10. 关于MySQL Server影响ASP.NET网站使用的问题:未能加载文件或程序集MySql.Web.v20

    最近开发的ASP.NET MVC 4网站,之前头头说如果遇到装过MySQL的机器就绕着走,还觉得奇怪 嘛,该来的迟早都会来 于是撞上了一台 启动网站再访问,总是出错,提示“未能加载文件或程序集”,名字 ...