获取web应用路径 // "/" 表示class 根目录
2014-08-04 12:26
465 查看
/**
* 获取web应用路径
* @Description : 方法描述
* @Method_Name : getRootPath
* @return
* @return : String
* @Creation Date : 2013-12-13 下午9:09:28
* @version : v1.00
* @throws UnsupportedEncodingException
* @Author : zyn
* @Update Date :
* @Update Author : zyn
*/
public static String getRootPath() throws UnsupportedEncodingException {
String classPath = WebHelper.class.getClassLoader().getResource("/").getPath();
// "/" 表示class 根目录
String rootPath = "";
// windows下
if ("\\".equals(File.separator)) {
rootPath = classPath.substring(1, classPath.indexOf("/WEB-INF/classes"));
rootPath = rootPath.replace("/", "\\");
rootPath = URLDecoder.decode(rootPath, "UTF-8");
}
// linux下
if ("/".equals(File.separator)) {
rootPath = classPath.substring(0, classPath.indexOf("/WEB-INF/classes"));
rootPath = rootPath.replace("\\", "/");
rootPath = URLDecoder.decode(rootPath, "UTF-8");
}
return rootPath;
}
* 获取web应用路径
* @Description : 方法描述
* @Method_Name : getRootPath
* @return
* @return : String
* @Creation Date : 2013-12-13 下午9:09:28
* @version : v1.00
* @throws UnsupportedEncodingException
* @Author : zyn
* @Update Date :
* @Update Author : zyn
*/
public static String getRootPath() throws UnsupportedEncodingException {
String classPath = WebHelper.class.getClassLoader().getResource("/").getPath();
// "/" 表示class 根目录
String rootPath = "";
// windows下
if ("\\".equals(File.separator)) {
rootPath = classPath.substring(1, classPath.indexOf("/WEB-INF/classes"));
rootPath = rootPath.replace("/", "\\");
rootPath = URLDecoder.decode(rootPath, "UTF-8");
}
// linux下
if ("/".equals(File.separator)) {
rootPath = classPath.substring(0, classPath.indexOf("/WEB-INF/classes"));
rootPath = rootPath.replace("\\", "/");
rootPath = URLDecoder.decode(rootPath, "UTF-8");
}
return rootPath;
}
相关文章推荐
- (tomcat中级)应用Tomcat的WebappClassLoader加载指定目录的jar文件
- JAVA 取得当前目录的路径/Servlet/class/文件路径/web路径/url地址
- 获取应用程序根目录物理路径(Web and Windows)
- 从request获取各种路径总结 request.getRealPath("url"); // 虚拟目录映射为实际目录 request.getRealPat
- java 工程获取路径 web根目录。 项目classpath根目录 各种实用方法 摘抄收藏
- .net下获取Web应用目录方法
- JAVA-servelet 取得当前目录的路径/Servlet/class/文件路径/web路径/url地址
- Java获取WEB目录路径
- Weblogic web应用中获取文件的绝对路径
- JAVA 取JAVA 取得当前目录的路径/Servlet/class/文件路径/web路径/url地址 得当前目录的路径/Servlet/class/文件路径/web路径/url地址
- Java在不同环境下获取当前路径的方法--this.getClass().getResource("")
- Java在不同环境下获取当前路径的方法--this.getClass().getResource("")
- java类获取web应用的根目录(转载)
- IOS 应用获取应用程序目录的路径分析
- Spring 获取web根目录 (Spring线程获取web目录/路径/根目录,普通类获取web目录)
- java类获取web应用的根目录
- Java在不同环境下获取当前路径的方法--this.getClass().getResource("")
- Java获取WEB目录路径
- java 工程获取路径 web根目录。 项目classpath根目录 各种实用方法
- java 工程获取路径 web根目录。 项目classpath根目录 各种实用方法 摘抄收藏