Java中获取文件路径
1、实例说明
(1)得到 ClassPath的绝对URI路径
Thread.currentThread().getContextClassLoader().getResource(".").getPath();
Thread.currentThread().getContextClassLoader().getResource("").getPath();
System.getProperty("user.dir");
/**
* @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);
}
}
/D:/eclipse/workspace/HighCharts/build/classes/ /D:/eclipse/workspace/HighCharts/build/classes/ D:\eclipse\workspace\HighCharts
原文:http://blog.csdn.net/you23hai45/article/details/22526739