• Java中获取文件路径


    Java中获取文件路径


    1、实例说明

    (1)得到 ClassPath的绝对URI路径

    Thread.currentThread().getContextClassLoader().getResource(".").getPath();

    (2)得到 ClassPath的绝对URI路径

    Thread.currentThread().getContextClassLoader().getResource("").getPath();

    (3)得到工程的路径

    System.getProperty("user.dir");

    2、实例源码

    /**
     * @Title:FilePath.java
     * @Package:com.you.model
     * @Description:
     * @Author: 游海东
     * @date: 2014年3月29日 上午11:42:16
     * @Version V1.2.3
     */
    package com.you.model;
    
    /**
     * @类名:FilePath
     * @描述:
     * @Author:游海东
     * @date: 2014年3月29日 上午11:42:16
     */
    public class FilePath {
    
    	/**
    	 * @Title : main
    	 * @Type : FilePath
    	 * @date : 2014年3月29日 上午11:42:17
    	 * @Description : 
    	 * @param args
    	 */
    	public static void main(String[] args) 
    	{
    		/**
    		 * 得到 ClassPath的绝对URI路径
    		 */
            	String str1 = Thread.currentThread().getContextClassLoader().getResource(".").getPath();
           		 /**
             	  * 得到 ClassPath的绝对URI路径
            	  */
            	String str2 = Thread.currentThread().getContextClassLoader().getResource("").getPath();
           		 /**
            	   * 得到工程的路径
            	  */
           		 String str3 = System.getProperty("user.dir");
           		 System.out.println(str1);
           		 System.out.println(str2);
           		 System.out.println(str3);
    	}
    
    }
    

    3、实例结果

    /D:/eclipse/workspace/HighCharts/build/classes/
    /D:/eclipse/workspace/HighCharts/build/classes/
    D:eclipseworkspaceHighCharts
    


  • 相关阅读:
    csr_matrix参数解析
    SQL删除重复数据(根据多个字段),pandas的nan存入数据库报错
    XGBoost参数中文翻译以及参数调优
    pandas.DataFrame.quantile
    pandas.DataFrame.rank
    JOIN子句
    ORDER BY子句
    WHERE子句
    SELECT语句
    数据分析-基础
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315244.html
Copyright © 2020-2023  润新知