1. 程式人生 > >java獲取webroot下面的檔案路徑

java獲取webroot下面的檔案路徑

/**
	 * 
	 * @return WebRoot目錄的絕對路徑
	 */
	public static String getWebRootAbsolutePath() {
		String path = null;
		String folderPath = Path.class.getProtectionDomain().getCodeSource()
				.getLocation().getPath();
		if (folderPath.indexOf("WEB-INF") > 0) {
			path = folderPath.substring(0, folderPath
					.indexOf("WEB-INF/classes"));
		}
		return path;
	}