zoukankan      html  css  js  c++  java
  • java、struts、tomcat程序中的各种取路径的方法

    全文见  

    ****************
    得到当前路径
    File f = new File(".");
    String absolutePath = f.getAbsolutePath();
    System.out.println(absolutePath);

    1.路径中空格:

    String pathtem=null;
    URL ut=Thread.currentThread().getContextClassLoader().getResource("");
    pathtem=ut.toString();
    pathtem=pathtem.replace("%20", " ");//去掉空格
    pathtem=pathtem.substring(6,pathtem.length());//去掉"file:/"
    返回:
    d:/apache/webapp/Ev/WEB-INF/classes/

    2.生成jar包后
            String pathtem=null;
            URL ut=Csssb_se.class.getResource("");
            pathtem=ut.toString();
            pathtem=pathtem.replace("%20", " ");
            pathtem=pathtem.substring(0,pathtem.indexOf(projectname));
            pathtem=pathtem.replace("file:///","");
            pathtem=pathtem.replace("file:/","");
            pathtem=pathtem.replace("jar:","");
        
    3.生成war包后,Tomcat

            String Dirpath = null;
            String Project_name = "TranData";
            URL ut = Thread.currentThread().getContextClassLoader().getResource("");
            Dirpath = ut.toString();
            Dirpath = Dirpath.replace("%20", " ");
            Dirpath = Dirpath.substring(6, Dirpath.length());
            int project_name_index = Dirpath.indexOf(Project_name);
            Dirpath = Dirpath.substring(0, project_name_index
                    + Project_name.length() + 1);

            String xmlfilepath = Dirpath + "s.xml";
     


  • 相关阅读:
    awk线程号
    std::string::substr函数
    计数器表的简单使用
    vim + oh-my-zsh + git搭建开发环境
    <<代码大全>>阅读笔记之二 变量名的力量
    <<代码大全>>阅读笔记之一 使用变量的一般事项
    压测工具ab的简单使用
    nginx配置文件详解
    numba初体验
    Linux查找文件内容小技巧
  • 原文地址:https://www.cnblogs.com/chenzhihong/p/2281665.html
Copyright © 2011-2022 走看看