重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

C#读写文件

1、C#读文件
按行读取文件:

创新互联公司主营鄠邑网站建设的网络公司,主营网站建设方案,app开发定制,鄠邑h5微信小程序搭建,鄠邑网站营销推广欢迎鄠邑等地区企业咨询

public void Read(string path)
        {
            StreamReader sr = new StreamReader(path,Encoding.Default);
            String line;
            while ((line = sr.ReadLine()) != null) 
            {
                Console.WriteLine(line.ToString());
            }
        }

2、写文件

        public void Write(string path)
        {
            FileStream fs = new FileStream(path, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
            //开始写入
            sw.Write("Hello World!!!!");
            //清空缓冲区
            sw.Flush();
            //关闭流
            sw.Close();
            fs.Close();
        }

新闻名称:C#读写文件
链接URL:http://cqcxhl.cn/article/igshjs.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP