码迷,mamicode.com
首页 > Windows程序 > 详细

C# 将内容写入txt文档

时间:2015-08-27 01:56:59      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

<1>  FileStream fs = new FileStream(@"D:\text.txt", FileMode.Append);

        StreamWriter sw = new StreamWriter(fs, Encoding.Default);

        sw.Write(strAnalasy);

        sw.Close();

        fs.Close();

<2>  FileStream TreatProcess = new FileStream(@"文件目录", FileMode.Append);

        TreatProcess.Write(receiveData, i + 2, 4);

        TreatProcess.Close();

    稳定的写入txt文件的方式:

        FileStream fs = new FileStream("zhanglei.txt", FileMode.Create);

        byte[] data = System.Text.Encoding.Default.GetBytes("a" + System.Environment.NewLine +"b");

        fs.Write(data, 0, data.Length);

        fs.Flush();

        fs.Close();

    稳定的读txt文档的方式:

       StreamReader sr = new StreamReader("zhanglei.txt", Encoding.Default);

       string line = null;

       while ((line = sr.ReadLine()) != null)

       {

             MessageBox.Show(line);

       }

       sr.Close();

C# 将内容写入txt文档

标签:

原文地址:http://www.cnblogs.com/zhanglei93/p/4762027.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!