streamwriter写入html,C# StreamWrite和StreamReader 读写操作

摘要:

StreamWrite和StreamReader 读写操作using System;

using System.IO;

using System.Text;

namespace StreamWrite和StreamReader

{

class Program

{

StreamWrite和StreamReader 读写操作using System;

using System.IO;

using System.Text;

namespace StreamWrite和StreamReader

{

class Program

{

static void Main(string[] args)

{

using (StreamWriter sw = new StreamWriter(@"D:\Users\Desktop\小道博客.txt", true, Encoding.UTF8))//写入,追加文本(true)

{

sw.Write("站名:");//写入

sw.WriteLine("小道博客");//写入行

sw.Write("网址:");//写入

sw.WriteLine("http://www.daobk.com");//写入行

Console.WriteLine("写入成功!按任意键读取.");//提示

}

using (StreamReader sr = new StreamReader(@"D:\Users\Desktop\小道博客.txt", Encoding.UTF8))//读取

{

//第一种读取方法

while (!sr.EndOfStream)//获取一个值,该值表示当前的流位置是否在流的末尾。(如果当前流位置位于流的末尾,则为 true;否则为 false。)取非

{

string str = sr.ReadLine();//从当前流中读取一行字符并将数据作为字符串返回。

Console.WriteLine(str);//输出

}

//第二种读取方法

//string s = null;//声明字符串 为null

//while ((s = sr.ReadLine()) != null)// sr.ReadLine() 返回结果 输入流中的下一行;如果到达了输入流的末尾,则为 null。,判断读取数据是否不为空,不为空则为真 继续读取

//{

//    Console.WriteLine(s);//输出

//}

Console.WriteLine("读取完成!");//提示

}

Console.ReadKey();//按任意键

}

}

}

输出结果:

23793ceb7c45622fbdc55deaaddc1d25.png

db2fafbb32d56b60e13c63b4e352047c.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值