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("\\", "/");
    }

  • 相关阅读:
    练习1-6
    c语言while(1)和while(0)
    练习1-3
    每天总结模电--(三)
    每天总结模电——贴片电阻,电容的命名规则(二)
    服务器应用的通用功能
    UML
    算法合集
    python笔记
    笔面试(2019秋招阶段)
  • 原文地址:https://www.cnblogs.com/zengdingxin/p/3133582.html
Copyright © 2011-2022 走看看