c#添加删除文件

HttpRequest request = HttpContext.Current.Request;
            HttpResponse response = HttpContext.Current.Response;
            request.ContentType = "json";
            response.ContentType = "json";

            StreamReader reader = new StreamReader(request.InputStream);
            string test = reader.ReadToEnd();
            //写入文本
            const string fileName = "2.json";
            string filepath = Server.MapPath("." + "\\" + fileName);
            try
            {
                if (File.Exists(filepath))
                {
                    string delFile = filepath;
                    File.Delete(delFile);
                }

                using (StreamWriter sw = File.CreateText(filepath))
                {


                    sw.Write(test);
                    sw.Close();
                }
            }
            catch (Exception)
            {
                response.Write("{\"result\":\"sorry\"}");
                return;
            }
            response.Write("{\"result\":\"ok\"}");
        }

你可能感兴趣的:(C++,c,json,C#)