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什么來着 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM