当前位置:首页 > Windows程序 > 正文

Encoding.Default);String line;while ((line = sr.ReadLine())

2024-03-31 Windows程序

标签:

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

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(); }

标签:

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/35456.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494590访问次数
  • 建站天数
  • 友情链接