將指定字符串內容寫入到簡單類型的文件,路徑的文件後綴名決定了文件的具體類型。html
/// <summary> /// 將指定字符串內容寫入到html文件,若已存在則覆蓋 /// </summary> /// <param name="str">要寫入的字符串</param> /// <param name="fileName">html文件的路徑</param> private void WriteToHtml(string str, string fileName) { try { FileStream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write); byte[] byteSave = Encoding.UTF8.GetBytes(str); fileStream.Write(byteSave, 0, byteSave.Length); fileStream.Flush(); fileStream.Close(); } catch (Exception e) { throw e; } }