• 获取服务器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;
        }
  • 相关阅读:
    PHP静态
    PHP批量删除
    PHP增删改查
    PHP数据访问
    PHP继承和多态
    PHP封装
    PHP字符串处理和正则表达式
    PHP数组
    PHP函数
    PHP基础
  • 原文地址:https://www.cnblogs.com/sallet/p/3941582.html
Copyright © 2020-2023  润新知