Net Core教程

c#文件的读写

本文主要是介绍c#文件的读写,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

//写
using (FileStream fs = File.Create(filename))
{
  byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
  fs.Write(info, 0, info.Length);
}

//读
using (StreamReader sr = File.OpenText(filename))
{
  string s = "";
  while ((s = sr.ReadLine()) != null)
  {
    DisplayAlert("read", s, "");
  }
}

这篇关于c#文件的读写的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!