zoukankan      html  css  js  c++  java
  • 获取服务器classes根路径

    /**
        *     获取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 = Object.class.getClass().getResource("/").getPath();
            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;
        }
  • 相关阅读:
    mysql优化
    c语言学习的第10天
    学习c语言的第9天
    学习c的第8天
    学习c的第7天
    学习c的第6天2
    c语言学习的第6天
    sed命令实战
    grep命令实战
    c语言学习的第五天
  • 原文地址:https://www.cnblogs.com/sallet/p/3941582.html
Copyright © 2011-2022 走看看