Java路径获取
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java路径获取,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2511字,纯文字阅读大概需要4分钟。
内容图文
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
原文:http://www.cnblogs.com/yfceshi/p/6917847.html
内容总结
以上是互联网集市为您收集整理的Java路径获取全部内容,希望文章能够帮你解决Java路径获取所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。