1. 程式人生 > >普通java類獲取專案的根目錄

普通java類獲取專案的根目錄

import org.springframework.web.servlet.support.RequestContext;
//獲取專案的classes目錄,例如:D:/songjinzhou/software/apache-tomcat-7.0.52/webapps/專案名/WEB-INF/classes/
String root = RequestContext.class.getResource("/").getFile();
//獲取專案根目錄,例如:D:\songjinzhou\software\apache-tomcat-7.0.52\webapps\專案名
String templateFilePath = new File(root).getParentFile().getParentFile().getCanonicalPath()+"/excel_template/abc.xls"