zoukankan      html  css  js  c++  java
  • 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() = 
    " + test03.getPathByPoint());
    		System.out.println("this.getClass().getClassLoader().getResource("").getPath() = 
    " + test03.getPathByNothing());
    		
    		System.out.println("this.getClass().getResource("").getPath() = 
    " + test03.getResourcePath());
    		System.out.println("this.getClass().getResource(".").getPath() = 
    " + test03.getResourcePathByPoint());
    		
    		System.out.println("Thread.currentThread().getContextClassLoader().getResource("").getPath() = 
    " + test03.getThreadPath());
    		System.out.println("Thread.currentThread().getContextClassLoader().getResource(".").getPath() = 
    " + 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:javajava_workspaceThinkingInJava
    F:javajava_workspaceThinkingInJavain;F:javajava_workspacecodemindview.jar
    


    
       
    
  • 相关阅读:
    转:matplotlib画图,plt.xx和ax.xx之间有什么差异
    转:Python __call__()方法,可调用对象
    训练集,验证集,测试集,交叉验证
    Visio画图和导出图的时候,去除多余白色背景
    在线jupyter notebook
    dfs序
    codeforces 877b
    codeforce864d
    codeforce868c
    查看本地git查看git公钥,私钥的方式
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6917847.html
Copyright © 2011-2022 走看看