分类: Java
2011-07-24 14:36:05
// 获取绝对根路径
public static String getAbsoluteRootPath() {
String rootPath = Thread.currentThread().getContextClassLoader()
.getResource("").toString();
String headStr = "file:/";
if (rootPath.startsWith(headStr)) {
rootPath = rootPath.substring(headStr.length());
} else if (rootPath.startsWith("/")) {
rootPath = rootPath.substring(1);
}
return rootPath;
}
// 获取绝对路径
public static String getAbsolutePath(String relativePath) {
return getAbsoluteRootPath() + relativePath;
}