java 获取服务器端的webapps路径

/**
	 * 获取服务器端的webapps路径
	 * @return
	 */
	public String findServerPath(){
		String classPath = this.getClass().getClassLoader().getResource("/").getPath();
        try {
            classPath =URLDecoder.decode(classPath, "gb2312");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
		String[] strPath = classPath.split("/");
		String path = "";
		for(int i = 0;i < strPath.length ; i++){
			if(i > 0 && i <= 3){
				path = path + strPath[i]+"/";
			}
		}
		return path;
	}
 
备注:
String filePath = System.getProperty("user.dir")+File.separator+"src"+File.separator+"main"+File.separator+"webapp"+File.separator+"downloads"+File.separator;



你可能感兴趣的:(java 获取服务器端的webapps路径)