Forcing StreamWriter to change Encoding

后端 未结 5 1220
没有蜡笔的小新
没有蜡笔的小新 2020-12-14 06:58

I am trying to save a file using DialogResult and StringBuilder. After making the text, I am calling the following code to save the file:



        
5条回答
  •  伪装坚强ぢ
    2020-12-14 07:25

    There is a constructor for filename, appendMode, encoding.

    With a proper using block it looks like:

    if (dr == DialogResult.OK)
    {
        using (StreamWriter sw = new StreamWriter(saveFileDialog1.FileName, 
               false, Encoding.UTF8))
        {
          sw.Write(sb.ToString());
          //sw.Close();
        }
    }
    

提交回复
热议问题