现在的位置: 首页 > 综合 > 正文

write data into a txt file in C#

2013年01月21日 ⁄ 综合 ⁄ 共 462字 ⁄ 字号 评论关闭

[1].StreamWriter variable declaration
public static System.IO.StreamWriter streamWriter;
[2].initialize of the variable
streamWriter = new System.IO.StreamWriter("filePath", false, System.Text.Encoding.GetEncoding("gb2312"));
[3].Write a string to the stream
streamWriter.Write(str);
[4].Clears all buffers for the current writer and cased any buffered data to be writen to the underlying stream

streamWriter.Flush();

[5].Reclamation of the writer when no more use it
if (streamWriter != null)
{
   streamWriter.Close();
}

抱歉!评论已关闭.