JAVA中获取当前执行路径

1)方式一

URI webPathTemp = Thread.currentThread().getContextClassLoader().getResource("").toURI();
 String webPath=String.valueOf(webPathTemp.getPath());
 webPath = webPath.substring(1,webPath.indexOf("WEB-INF"))+"out/zxjl";
 String templateFile=webPath+"/zxjl.dot";

2)方式二

String webPath = JSPUtil.class.getResource("").getPath();
   String xmlFile = webPath.substring(1,webPath.indexOf("WEB-INF"))+"out\\UpDownData.xml";

原文地址:https://www.cnblogs.com/willpower/p/1266941.html