zoukankan      html  css  js  c++  java
  • 获取项目物理根目录绝对路径

    //获取项目物理根目录绝对路径
        private String getWebAppRootPath(){
            String result = TimerTask.class.getResource("TimerTask.class").toString();
            int index = result.indexOf("WEB-INF");
            
            result = result.substring(0, index);
            if (result.startsWith("zip")) { // 当class文件在war中时,返回"zip:D:/ ..."样的路径
                result = result.substring(4);
            }
            else if (result.startsWith("file")) { // 当class文件在class文件中时,返回"file:/F:/ ..."样的路径
                result = result.substring(6);
            }else if(result.startsWith("jar")){ // 当class文件在jar文件中时,返回"jar:file:/F:/ ..."样的路径
                result = result.substring(10);
            }
            if (result.endsWith("/")) result = result.substring(0, result.length() - 1);// 不包含最后的"/"
                result = result.replace("%20", " "); //Window下替换空格
                return result;
            }

    //windows下
    if("\\".equals(File.separator)){
    template = template.replace("/", "\\");
    path = path.replace("/", "\\");
    }
    //linux下
    if("/".equals(File.separator)){
    template = template.replace("\\", "/");
    path = path.replace("\\", "/");
    }

  • 相关阅读:
    Django多表操作
    Django单表操作
    Django模板语言的复用
    DTL
    Django视图层、虚拟环境
    Django路由详解
    初识Django
    web框架
    JQ初级
    linux的基础配置命令
  • 原文地址:https://www.cnblogs.com/zengdingxin/p/3133582.html
Copyright © 2011-2022 走看看