1. 程式人生 > >獲取Tomcat同級目錄

獲取Tomcat同級目錄

//1.專案路徑

String projectPath = request.getSession().getServletContext().getRealPath("/");

//2.tomcat同級路徑

String tomcatPath = new File(projectPath ).getParentFile().getParentFile().getAbsolutePath();

//3.列印測試

System.out.println("專案路徑projectPath =" + projectPath );

System.out.println( "Tomcat同級目錄tomcatPath=" + tomcatPath);

我的測試列印結果為:

專案真實路徑relPath=E:\Justin\Softwares\LearningSoftwares\apache-tomcat-7.0.52\webapps\TestSSM\

Tomcat同級absolutePath=E:\JAGO\Softwares\LearningSoftwares\apache-tomcat-7.0.52