winform 写入txt

Posted on 2014-09-26 17:16  月下小王子  阅读(567)  评论(0编辑  收藏  举报

StreamWriter sw;

FileStream fs = new FileStream(@"D:\" + txtStringfield03.Text + ".txt", FileMode.OpenOrCreate, FileAccess.Write);
                            sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));
                            sw.Flush();
                            sw.BaseStream.Seek(0, SeekOrigin.Begin);
                            ee.Opens(strFileDrls);

 

sw.WriteLine();
                    sw.WriteLine();
                    sw.WriteLine(p_DECD);
                    sw.WriteLine();
                    sw.WriteLine();

sw.Flush();
sw.Close();

但是在这个程序中加入txt文件的名称存在,将会自动重写您的这个文件