获取当前绝对路径的方法

public static string GetMapPath(string strPath)
        {
            if (HttpContext.Current != null)
            {
                return HttpContext.Current.Server.MapPath(strPath);
            }
            else //非web程序引用
            {
                if (strPath.StartsWith(“~/“))
                    strPath = strPath.Substring(2);
                else if (strPath.StartsWith(“/“))
                    strPath = strPath.Substring(1);
                return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
            }
        }


注意:要引用System.Web命名空间

你可能感兴趣的:(java,Web)