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://whjierui.cn/article/igshjs.html

其他资讯