快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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#读写文件
文章路径:http://6mz.cn/article/igshjs.html

其他资讯