zoukankan      html  css  js  c++  java
  • java获取当前工程目录

    public class PathUtil {
    
    
    public static void main(String[] args)throws Exception {
       PathUtil p = new PathUtil();
       System.out.println(p.getWebClassesPath());
       System.out.println(p.getWebInfPath());
       System.out.println(p.getWebRoot());
    }
    
    public String getWebClassesPath() {
       String path = getClass().getProtectionDomain().getCodeSource()
         .getLocation().getPath();
       return path;
      
    }
    
    public String getWebInfPath() throws IllegalAccessException{
       String path = getWebClassesPath();
       if (path.indexOf("WEB-INF") > 0) {
        path = path.substring(0, path.indexOf("WEB-INF")+8);
       } else {
        throw new IllegalAccessException("路径获取错误");
       }
       return path;
    }
    
    public String getWebRoot() throws IllegalAccessException{
       String path = getWebClassesPath();
       if (path.indexOf("WEB-INF") > 0) {
        path = path.substring(0, path.indexOf("WEB-INF/classes"));
       } else {
        throw new IllegalAccessException("路径获取错误");
       }
       return path;
    }
    } 
  • 相关阅读:
    抽象类、接口
    静态联编、动态联编
    多态
    QML、Qt Quick
    重载、多态、继承、封装
    异步消息postEvent更新界面
    联合体union
    使用 Git@OSC 管理代码
    excel数据生成sql insert语句
    excel数据生成sql insert语句
  • 原文地址:https://www.cnblogs.com/aloe/p/2674411.html
Copyright © 2011-2022 走看看