C# 创建文件释放 Dispose()

System.IO.File.Create("文件路径")

前提确保有此路径, 否则会报错

本以为创建文件是会自动释放的, 结果没有自动释放 , 

fs.Write(responseBytes, 0, responseBytes.Length);
                        fs.Close();
                        UTF8Encoding utf8 = new UTF8Encoding(false);
                        String spath = RcvPath + "/xml/sdata.json";
                        if (!File.Exists(spath))
                        {
                            String sFloderpath = RcvPath + "/xml";
                            if (!Directory.Exists(sFloderpath))
                            {
                                Directory.CreateDirectory(sFloderpath);

                            }
                            System.IO.File.Create(spath).Dispose();
                        }
                        StreamWriter strMyCreate = new StreamWriter(spath, false, utf8);
                        String lastupdatetime = downloadWebClient.ResponseHeaders.GetValues("lastupdatetime")[0].ToString();
                        strMyCreate.WriteLine("{"lastUpdateTime":"" + lastupdatetime + ""}");
                        strMyCreate.Close();

  结果造就了第一次只创建文件 , 并不写入 , 执行第二次的时候才会写入

Dispose是创建文件后释放 , 好像是W3P什么来着 

原文地址:https://www.cnblogs.com/sunjinggege/p/10919399.html