1. 程式人生 > >在spring web專案中獲取WEB-INF/classes目錄與WEB-INF/目錄

在spring web專案中獲取WEB-INF/classes目錄與WEB-INF/目錄

場景:在spring web專案中獲取WEB-INF/classes目錄與WEB-INF/目錄
 1.獲取WEB-INF/classes 目錄 

        /**1.獲取WEB-INF/classes 目錄  **/
	public static String getWebRootPath() {
		String webRootPath = CommonConfigUtils.class.getResource("/").getPath();
		return webRootPath;
	}

2.獲取WEB-INF/

        /**2.獲取WEB-INF/   目錄*/
	public static String getWebInfPath() {
		String webRootPath = CommonConfigUtils.class.getResource("/").getPath();
		String webInfPath = webRootPath.substring(0,webRootPath.indexOf("classes"));
		return webInfPath;
	}

 以上,TKS.