C# 建立文件釋放 Dispose()

System.IO.File.Create("文件路徑")json

前提確保有此路徑, 不然會報錯spa

本覺得建立文件是會自動釋放的, 結果沒有自動釋放 , xml

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();

  結果造就了第一次只建立文件 , 並不寫入 , 執行第二次的時候纔會寫入blog

Dispose是建立文件後釋放 , 好像是W3P什麼來着 it

相關文章
相關標籤/搜索