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

  • 相关阅读:
    DAG:区块链行业下一个引爆点?
    php7的新特性
    Linux中的冷热页机制概述
    撰写后台需求文档需要注意的那些事儿
    poj 1201 Intervals
    poj 1364
    poj Candies
    hdu 1429
    poj A Round Peg in a Ground Hole
    poj 1113Wall
  • 原文地址:https://www.cnblogs.com/zengdingxin/p/3133582.html
Copyright © 2011-2022 走看看